3 // Demonstrate the use of the unguarded escape hatch with a type param in negative position
4 // to assert that destructor will not access any dead data.
6 // Compare with ui/span/issue28498-reject-lifetime-param.rs
8 // Demonstrate that a type param in negative position causes dropck to reject code
9 // that might indirectly access previously dropped value.
11 // Compare with run-pass/issue28498-ugeh-with-passed-to-fn.rs
13 #![feature(dropck_eyepatch)]
16 struct ScribbleOnDrop(String);
18 impl Drop for ScribbleOnDrop {
20 self.0 = format!("DROPPED");
24 struct Foo<T>(u32, T, #[allow(unused_tuple_struct_fields)] Box<for <'r> fn(&'r T) -> String>);
26 unsafe impl<#[may_dangle] T> Drop for Foo<T> {
28 // Use of `may_dangle` is sound, because destructor never passes a `self.1`
29 // to the callback (in `self.2`) despite having it available.
30 println!("Dropping Foo({}, _)", self.0);
34 fn callback(s: & &ScribbleOnDrop) -> String { format!("{:?}", s) }
37 let (last_dropped, foo0);
38 let (foo1, first_dropped);
40 last_dropped = ScribbleOnDrop(format!("last"));
41 first_dropped = ScribbleOnDrop(format!("first"));
42 foo0 = Foo(0, &last_dropped, Box::new(callback));
43 foo1 = Foo(1, &first_dropped, Box::new(callback));
45 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);