1 // aux-build:dropck_eyepatch_extern_crate.rs
3 // The point of this test is to illustrate that the `#[may_dangle]`
4 // attribute specifically allows, in the context of a type
5 // implementing `Drop`, a generic parameter to be instantiated with a
6 // lifetime that does not strictly outlive the owning type itself,
7 // and that this attribute's effects are preserved when importing
8 // the type from another crate.
10 // See also dropck-eyepatch.rs for more information about the general
11 // structure of the test.
12 extern crate dropck_eyepatch_extern_crate as other;
14 use other::{Dt,Dr,Pt,Pr,St,Sr};
19 // We use separate blocks with separate variable to prevent the error
20 // messages from being deduplicated.
24 let (mut dt, mut dr): (Dt<_>, Dr<_>);
25 c_long = Cell::new(1);
27 // No error: sufficiently long-lived state can be referenced in dtors
28 dt = Dt("dt", &c_long);
29 dr = Dr("dr", &c_long);
33 let (c, mut dt, mut dr): (Cell<_>, Dt<_>, Dr<_>);
36 // No Error: destructor order precisely modelled
42 let (mut dt, mut dr, c_shortest): (Dt<_>, Dr<_>, Cell<_>);
43 c_shortest = Cell::new(1);
45 // Error: `c_shortest` dies too soon for the references in dtors to be valid.
46 dt = Dt("dt", &c_shortest);
47 //~^ ERROR `c_shortest` does not live long enough
48 dr = Dr("dr", &c_shortest);
53 let (mut pt, mut pr, c_shortest): (Pt<_, _>, Pr<_>, Cell<_>);
54 c_long = Cell::new(1);
55 c_shortest = Cell::new(1);
57 // No error: Drop impl asserts .1 (A and &'a _) are not accessed
58 pt = Pt("pt", &c_shortest, &c_long);
59 pr = Pr("pr", &c_shortest, &c_long);
64 let (mut pt, mut pr, c_shortest): (Pt<_, _>, Pr<_>, Cell<_>);
65 c_long = Cell::new(1);
66 c_shortest = Cell::new(1);
67 // Error: Drop impl's assertion does not apply to `B` nor `&'b _`
68 pt = Pt("pt", &c_long, &c_shortest);
69 //~^ ERROR `c_shortest` does not live long enough
70 pr = Pr("pr", &c_long, &c_shortest);
74 let (st, sr, c_shortest): (St<_>, Sr<_>, Cell<_>);
75 c_shortest = Cell::new(1);
76 // No error: St and Sr have no destructor.
77 st = St("st", &c_shortest);
78 sr = Sr("sr", &c_shortest);
82 fn use_imm<T>(_: &T) { }