1 // Copyright 2016 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 #![feature(rustc_attrs)]
13 // check that panics in destructors during assignment do not leave
14 // destroyed values lying around for other destructors to observe.
16 // error-pattern:panicking destructors ftw!
18 struct Observer<'a>(&'a mut FilledOnDrop);
20 struct FilledOnDrop(u32);
21 impl Drop for FilledOnDrop {
24 // this is only set during the destructor - safe
25 // code should not be able to observe this.
27 panic!("panicking destructors ftw!");
32 impl<'a> Drop for Observer<'a> {
34 assert_eq!(self.0 .0, 1);
39 fn foo(b: &mut Observer) {
40 *b.0 = FilledOnDrop(1);
44 let mut bomb = FilledOnDrop(0);
45 let mut observer = Observer(&mut bomb);