Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
librustc: Make sure to run destructors in the right order when matchi…
…ng on moved value.
- Loading branch information
Showing
3 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
|
||
// Test to make sure the destructors run in the right order. | ||
// Each destructor sets it's tag in the corresponding entry | ||
// in ORDER matching up to when it ran. | ||
// Correct order is: matched, inner, outer | ||
|
||
static mut ORDER: [uint, ..3] = [0, 0, 0]; | ||
static mut INDEX: uint = 0; | ||
|
||
struct A; | ||
impl Drop for A { | ||
fn drop(&mut self) { | ||
unsafe { | ||
ORDER[INDEX] = 1; | ||
INDEX = INDEX + 1; | ||
} | ||
} | ||
} | ||
|
||
struct B; | ||
impl Drop for B { | ||
fn drop(&mut self) { | ||
unsafe { | ||
ORDER[INDEX] = 2; | ||
INDEX = INDEX + 1; | ||
} | ||
} | ||
} | ||
|
||
struct C; | ||
impl Drop for C { | ||
fn drop(&mut self) { | ||
unsafe { | ||
ORDER[INDEX] = 3; | ||
INDEX = INDEX + 1; | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
{ | ||
let matched = A; | ||
let _outer = C; | ||
{ | ||
match matched { | ||
_s => {} | ||
} | ||
let _inner = B; | ||
} | ||
} | ||
unsafe { | ||
assert_eq!(&[1, 2, 3], ORDER.as_slice()); | ||
} | ||
} |
1af8663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pnkfelix
at luqmana@1af8663
1af8663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging luqmana/rust/odp = 1af8663 into auto
1af8663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luqmana/rust/odp = 1af8663 merged ok, testing candidate = 342321d
1af8663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/187
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/188
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/188
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/188
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/191
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/192
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/191
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/197
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/192
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/191
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/194
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/192
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/191
1af8663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 342321d