aboutsummaryrefslogtreecommitdiff
path: root/tests/ui/project/type-mismatch.rs
blob: 41a70eb87bf3eec031df09d32de3885a1eaaddc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![feature(proc_macro_hygiene, stmt_expr_attributes)]

use pin_project::{pin_project, project};
use std::pin::Pin;

#[project]
fn type_mismatch() {
    #[pin_project]
    enum Enum<A, B, C, D> {
        Variant1(#[pin] A, B),
        Variant2 {
            #[pin]
            field1: C,
            field2: D,
        },
        None,
    }

    let mut foo = Enum::Variant1(1, 2);
    let mut foo = Pin::new(&mut foo).project();

    #[project]
    match &mut foo {
        Enum::Variant1(x, y) => {
            let x: &mut Pin<&mut i32> = x;
            assert_eq!(**x, 1);

            let y: &mut &mut i32 = y;
            assert_eq!(**y, 2);
        }
        Enum::Variant2 { field1, field2 } => {
            let _x: &mut Pin<&mut i32> = field1;
            let _y: &mut &mut i32 = field2;
        }
        None => {} //~ ERROR mismatched types
    }
}

//~ ERROR mismatched types
// span is lost.
// Refs: https://github.com/rust-lang/rust/issues/43081
fn type_mismatch_span_issue() {
    #[pin_project]
    enum Enum<A, B, C, D> {
        Variant1(#[pin] A, B),
        Variant2 {
            #[pin]
            field1: C,
            field2: D,
        },
        None,
    }

    let mut foo = Enum::Variant1(1, 2);
    let mut foo = Pin::new(&mut foo).project();

    #[project]
    match &mut foo {
        Enum::Variant1(x, y) => {
            let x: &mut Pin<&mut i32> = x;
            assert_eq!(**x, 1);

            let y: &mut &mut i32 = y;
            assert_eq!(**y, 2);
        }
        Enum::Variant2 { field1, field2 } => {
            let _x: &mut Pin<&mut i32> = field1;
            let _y: &mut &mut i32 = field2;
        }
        None => {}
    }
}

fn main() {}