1 // Demonstrate that having a trait bound causes dropck to reject code
2 // that might indirectly access previously dropped value.
4 // Compare with run-pass/issue28498-ugeh-with-trait-bound.rs
9 struct ScribbleOnDrop(String);
11 impl Drop for ScribbleOnDrop {
13 self.0 = format!("DROPPED");
17 struct Foo<T: fmt::Debug>(u32, T);
19 impl<T: fmt::Debug> Drop for Foo<T> {
21 // Use of `may_dangle` is unsound, because we access `T` fmt method when we pass
22 // `self.1` below, and thus potentially read from borrowed data.
23 println!("Dropping Foo({}, {:?})", self.0, self.1);
28 let (last_dropped, foo0);
29 let (foo1, first_dropped);
31 last_dropped = ScribbleOnDrop(format!("last"));
32 first_dropped = ScribbleOnDrop(format!("first"));
33 foo0 = Foo(0, &last_dropped); // OK
34 foo1 = Foo(1, &first_dropped);
35 //~^ ERROR `first_dropped` does not live long enough
37 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);