Skip to content

Commit 83084e9

Browse files
committed
auto merge of #10748 : kballard/rust/issue-10734-rpass, r=alexcrichton
Stop relying on a malloc error to indicate failure and instead use an explicit check. Also ensure that the value is dropped at the correct time (e.g. that the if statement is translated into `{ expr }` instead of `expr`).
2 parents b2aa00b + 2ffcbf1 commit 83084e9

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/test/run-pass/issue-10734.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,37 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
static mut drop_count: uint = 0;
12+
13+
#[unsafe_no_drop_flag]
14+
struct Foo {
15+
dropped: bool
16+
}
17+
18+
impl Drop for Foo {
19+
fn drop(&mut self) {
20+
// Test to make sure we haven't dropped already
21+
assert!(!self.dropped);
22+
self.dropped = true;
23+
// And record the fact that we dropped for verification later
24+
unsafe { drop_count += 1; }
25+
}
26+
}
27+
1128
pub fn main() {
29+
// An `if true { expr }` statement should compile the same as `{ expr }`.
1230
if true {
13-
let _a = ~3;
31+
let _a = Foo{ dropped: false };
1432
}
33+
// Check that we dropped already (as expected from a `{ expr }`).
34+
unsafe { assert!(drop_count == 1); }
35+
36+
// An `if false {} else { expr }` statement should compile the same as `{ expr }`.
1537
if false {
16-
fail!()
38+
fail!();
1739
} else {
18-
let _a = ~3;
40+
let _a = Foo{ dropped: false };
1941
}
42+
// Check that we dropped already (as expected from a `{ expr }`).
43+
unsafe { assert!(drop_count == 2); }
2044
}

0 commit comments

Comments
 (0)