]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/cleanup-arm-conditional.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / test / run-pass / cleanup-arm-conditional.rs
CommitLineData
0bf4aa26
XL
1#![allow(stable_features)]
2#![allow(unused_imports)]
1a4d82fc
JJ
3// Test that cleanup scope for temporaries created in a match
4// arm is confined to the match arm itself.
5
c34b1796
AL
6// pretty-expanded FIXME #23616
7
c34b1796 8#![feature(box_syntax, os)]
1a4d82fc
JJ
9
10use std::os;
11
c34b1796 12struct Test { x: isize }
1a4d82fc
JJ
13
14impl Test {
c34b1796 15 fn get_x(&self) -> Option<Box<isize>> {
1a4d82fc
JJ
16 Some(box self.x)
17 }
18}
19
c34b1796 20fn do_something(t: &Test) -> isize {
1a4d82fc
JJ
21
22 // The cleanup scope for the result of `t.get_x()` should be the
23 // arm itself and not the match, otherwise we'll (potentially) get
24 // a crash trying to free an uninitialized stack slot.
25
26 match t {
27 &Test { x: 2 } if t.get_x().is_some() => {
28 t.x * 2
29 }
30 _ => { 22 }
31 }
32}
33
34pub fn main() {
35 let t = Test { x: 1 };
36 do_something(&t);
37}