3 // Demonstrate the use of the unguarded escape hatch with a trait bound
4 // to assert that destructor will not access any dead data.
6 // Compare with ui/span/issue28498-reject-trait-bound.rs
8 #![feature(dropck_eyepatch)]
13 struct ScribbleOnDrop(String);
15 impl Drop for ScribbleOnDrop {
17 self.0 = format!("DROPPED");
21 struct Foo<T: fmt::Debug>(u32, T);
23 unsafe impl<#[may_dangle] T: fmt::Debug> Drop for Foo<T> {
25 // Use of `may_dangle` is sound, because destructor never accesses
26 // the `Debug::fmt` method of `T`, despite having it available.
27 println!("Dropping Foo({}, _)", self.0);
32 let (last_dropped, foo0);
33 let (foo1, first_dropped);
35 last_dropped = ScribbleOnDrop(format!("last"));
36 first_dropped = ScribbleOnDrop(format!("first"));
37 foo0 = Foo(0, &last_dropped);
38 foo1 = Foo(1, &first_dropped);
40 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);