aboutsummaryrefslogtreecommitdiff
path: root/tests/project_if_attr.rs.in
blob: a8ceeac501903ad32bee9d42d1f5744055823d8b (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
#[test]
#[project]
fn project_if_let() {
    #[pin_project]
    enum Foo<A, B> {
        Variant1(#[pin] A),
        Variant2(u8),
        Variant3 {
            #[pin] field: B
        }
    }

    let mut x: Foo<bool, f32> = Foo::Variant1(true);
    let x = Pin::new(&mut x).project();

    #[project]
    if let Foo::Variant1(a) = x {
        let a: Pin<&mut bool> = a;
        assert_eq!(*a, true);
    } else if let Foo::Variant2(_) = x {
        unreachable!();
    } else if let Foo::Variant3 { .. } = x {
        unreachable!();
    }
}

#[allow(clippy::unnecessary_operation, clippy::unit_arg)]
#[test]
#[project]
fn non_stmt_expr_if_let() {
    #[pin_project]
    enum Enum<A> {
        Variant(#[pin] A),
    }

    let mut x = Enum::Variant(1);
    let x = Pin::new(&mut x).project();

    #[allow(irrefutable_let_patterns)]
    Some(
        #[project]
        if let Enum::Variant(_x) = x {},
    );
}