1 // Demonstrate that having a lifetime param causes dropck to reject code
2 // that might indirectly access previously dropped value.
4 // Compare with run-pass/issue28498-ugeh-with-lifetime-param.rs
7 struct ScribbleOnDrop(String);
9 impl Drop for ScribbleOnDrop {
11 self.0 = format!("DROPPED");
15 struct Foo<'a>(u32, &'a ScribbleOnDrop);
17 impl<'a> Drop for Foo<'a> {
19 // Use of `may_dangle` is unsound, because destructor accesses borrowed data
20 // in `self.1` and we must force that to strictly outlive `self`.
21 println!("Dropping Foo({}, {:?})", self.0, self.1);
26 let (last_dropped, foo0);
27 let (foo1, first_dropped);
29 last_dropped = ScribbleOnDrop(format!("last"));
30 first_dropped = ScribbleOnDrop(format!("first"));
31 foo0 = Foo(0, &last_dropped); // OK
32 foo1 = Foo(1, &first_dropped);
33 //~^ ERROR `first_dropped` does not live long enough
35 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);