aboutsummaryrefslogtreecommitdiff
path: root/tests/ui/pin_project/remove-attr-from-struct.rs
blob: cbe5aba2344aa75cb49de79381d41a02e1f198a7 (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
use std::{marker::PhantomPinned, pin::Pin};

use auxiliary_macro::remove_attr;
use pin_project::pin_project;

fn is_unpin<T: Unpin>() {}

#[pin_project]
#[remove_attr(struct_all)]
struct A {
    #[pin] //~ ERROR cannot find attribute `pin` in this scope
    f: PhantomPinned,
}

#[remove_attr(struct_all)]
#[pin_project]
struct B {
    #[pin] //~ ERROR cannot find attribute `pin` in this scope
    f: PhantomPinned,
}

#[pin_project] //~ ERROR has been removed
#[remove_attr(struct_pin)]
struct C {
    f: PhantomPinned,
}

#[remove_attr(struct_pin)]
#[pin_project] // Ok
struct D {
    f: PhantomPinned,
}

fn main() {
    is_unpin::<A>(); //~ ERROR E0277
    is_unpin::<B>(); //~ ERROR E0277
    is_unpin::<D>(); // Ok

    let mut x = A { f: PhantomPinned };
    let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599

    let mut x = B { f: PhantomPinned };
    let _ = Pin::new(&mut x).project(); //~ ERROR E0277,E0599

    let mut x = D { f: PhantomPinned };
    let _ = Pin::new(&mut x).project(); //~ Ok
}