]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/issue-30380.rs
Changed issue number to 36105
[rust.git] / src / test / run-fail / issue-30380.rs
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.
4 //
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.
10
11 #![feature(rustc_attrs)]
12
13 // check that panics in destructors during assignment do not leave
14 // destroyed values lying around for other destructors to observe.
15
16 // error-pattern:panicking destructors ftw!
17
18 struct Observer<'a>(&'a mut FilledOnDrop);
19
20 struct FilledOnDrop(u32);
21 impl Drop for FilledOnDrop {
22     fn drop(&mut self) {
23         if self.0 == 0 {
24             // this is only set during the destructor - safe
25             // code should not be able to observe this.
26             self.0 = 0x1c1c1c1c;
27             panic!("panicking destructors ftw!");
28         }
29     }
30 }
31
32 impl<'a> Drop for Observer<'a> {
33     fn drop(&mut self) {
34         assert_eq!(self.0 .0, 1);
35     }
36 }
37
38 #[rustc_mir]
39 fn foo(b: &mut Observer) {
40     *b.0 = FilledOnDrop(1);
41 }
42
43 fn main() {
44     let mut bomb = FilledOnDrop(0);
45     let mut observer = Observer(&mut bomb);
46     foo(&mut observer);
47 }