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