]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/issue-30380.rs
Auto merge of #63994 - Centril:refactor-qualify-consts, r=spastorino,oli-obk
[rust.git] / src / test / run-fail / issue-30380.rs
1 // check that panics in destructors during assignment do not leave
2 // destroyed values lying around for other destructors to observe.
3
4 // error-pattern:panicking destructors ftw!
5
6 struct Observer<'a>(&'a mut FilledOnDrop);
7
8 struct FilledOnDrop(u32);
9 impl Drop for FilledOnDrop {
10     fn drop(&mut self) {
11         if self.0 == 0 {
12             // this is only set during the destructor - safe
13             // code should not be able to observe this.
14             self.0 = 0x1c1c1c1c;
15             panic!("panicking destructors ftw!");
16         }
17     }
18 }
19
20 impl<'a> Drop for Observer<'a> {
21     fn drop(&mut self) {
22         assert_eq!(self.0 .0, 1);
23     }
24 }
25
26 fn foo(b: &mut Observer) {
27     *b.0 = FilledOnDrop(1);
28 }
29
30 fn main() {
31     let mut bomb = FilledOnDrop(0);
32     let mut observer = Observer(&mut bomb);
33     foo(&mut observer);
34 }