2 #![allow(unreachable_code)]
3 // Issue #21486: Make sure that all structures are dropped, even when
4 // created via FRU and control-flow breaks in the middle of
7 use std::sync::atomic::{Ordering, AtomicUsize};
13 // println!("splat #{}", self.0);
20 struct Foo { n0: Noisy, n1: Noisy }
22 fn vals(&self) -> (u8, u8) { (self.n0.0, self.n1.0) }
25 fn leak_1_ret() -> Foo {
26 let _old_foo = Foo { n0: Noisy(1), n1: Noisy(2) };
27 Foo { n0: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
32 fn leak_2_ret() -> Foo {
33 let _old_foo = Foo { n0: Noisy(1), n1: Noisy(2) };
34 Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
39 // In this case, the control flow break happens *before* we construct
40 // `Foo(Noisy(1),Noisy(2))`, so there should be no record of it in the
42 fn leak_3_ret() -> Foo {
43 let _old_foo = || Foo { n0: Noisy(1), n1: Noisy(2) };
44 Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
51 assert_eq!(leak_1_ret().vals(), (3,4));
52 assert_eq!(0x01_02_03_04, event_log());
55 assert_eq!(leak_2_ret().vals(), (3,4));
56 assert_eq!(0x01_02_03_04, event_log());
59 assert_eq!(leak_3_ret().vals(), (3,4));
60 assert_eq!(0x03_04, event_log());
63 static LOG: AtomicUsize = AtomicUsize::new(0);
66 LOG.store(0, Ordering::SeqCst);
69 fn event_log() -> usize {
70 LOG.load(Ordering::SeqCst)
74 let old_log = LOG.load(Ordering::SeqCst);
75 let new_log = (old_log << 8) + tag as usize;
76 LOG.store(new_log, Ordering::SeqCst);