1 // Demonstrate that a type param in negative position causes dropck to reject code
2 // that might indirectly access previously dropped value.
4 // Compare with run-pass/issue28498-ugeh-with-passed-to-fn.rs
7 struct ScribbleOnDrop(String);
9 impl Drop for ScribbleOnDrop {
11 self.0 = format!("DROPPED");
15 struct Foo<T>(u32, T, Box<for <'r> fn(&'r T) -> String>);
17 impl<T> Drop for Foo<T> {
19 // Use of `may_dangle` is unsound, because we pass `T` to the callback in `self.2`
20 // below, and thus potentially read from borrowed data.
21 println!("Dropping Foo({}, {})", self.0, (self.2)(&self.1));
25 fn callback(s: & &ScribbleOnDrop) -> String { format!("{:?}", s) }
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, Box::new(callback)); // OK
34 foo1 = Foo(1, &first_dropped, Box::new(callback));
35 //~^ ERROR `first_dropped` does not live long enough
37 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);