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 // Issue #21486: Make sure that all structures are dropped, even when
12 // created via FRU and control-flow breaks in the middle of
17 use std
::sync
::atomic
::{Ordering, AtomicUsize}
;
23 // println!("splat #{}", self.0);
30 struct Foo { n0: Noisy, n1: Noisy }
32 fn vals(&self) -> (u8, u8) { (self.n0.0, self.n1.0) }
35 fn leak_1_ret() -> Foo
{
36 let _old_foo
= Foo { n0: Noisy(1), n1: Noisy(2) }
;
37 Foo { n0: { return Foo { n0: Noisy(3), n1: Noisy(4) }
},
42 fn leak_2_ret() -> Foo
{
43 let _old_foo
= Foo { n0: Noisy(1), n1: Noisy(2) }
;
44 Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) }
},
49 // In this case, the control flow break happens *before* we construct
50 // `Foo(Noisy(1),Noisy(2))`, so there should be no record of it in the
52 fn leak_3_ret() -> Foo
{
53 let _old_foo
= || Foo { n0: Noisy(1), n1: Noisy(2) }
;
54 Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) }
},
61 assert_eq
!(leak_1_ret().vals(), (3,4));
62 assert_eq
!(0x01_02_03_04, event_log());
65 assert_eq
!(leak_2_ret().vals(), (3,4));
66 assert_eq
!(0x01_02_03_04, event_log());
69 assert_eq
!(leak_3_ret().vals(), (3,4));
70 assert_eq
!(0x03_04, event_log());
73 static LOG
: AtomicUsize
= AtomicUsize
::new(0);
76 LOG
.store(0, Ordering
::SeqCst
);
79 fn event_log() -> usize {
80 LOG
.load(Ordering
::SeqCst
)
84 let old_log
= LOG
.load(Ordering
::SeqCst
);
85 let new_log
= (old_log
<< 8) + tag
as usize;
86 LOG
.store(new_log
, Ordering
::SeqCst
);