1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Demonstrate the use of the unguarded escape hatch with a lifetime param
12 // to assert that destructor will not access any dead data.
14 // Compare with compile-fail/issue28498-reject-lifetime-param.rs
16 #![feature(dropck_parametricity)]
19 struct ScribbleOnDrop(String);
21 impl Drop for ScribbleOnDrop {
23 self.0 = format!("DROPPED");
27 struct Foo<'a>(u32, &'a ScribbleOnDrop);
29 impl<'a> Drop for Foo<'a> {
30 #[unsafe_destructor_blind_to_params]
32 // Use of `unsafe_destructor_blind_to_params` is sound,
33 // because destructor never accesses `self.1`.
34 println!("Dropping Foo({}, _)", self.0);
39 let (last_dropped, foo0);
40 let (foo1, first_dropped);
42 last_dropped = ScribbleOnDrop(format!("last"));
43 first_dropped = ScribbleOnDrop(format!("first"));
44 foo0 = Foo(0, &last_dropped);
45 foo1 = Foo(1, &first_dropped);
47 println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1);