]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cleanup-arm-conditional.rs
Rollup merge of #60685 - dtolnay:spdx, r=nikomatsakis
[rust.git] / src / test / run-pass / cleanup-arm-conditional.rs
1 #![allow(stable_features)]
2 #![allow(unused_imports)]
3 // Test that cleanup scope for temporaries created in a match
4 // arm is confined to the match arm itself.
5
6 // pretty-expanded FIXME #23616
7
8 #![feature(box_syntax, os)]
9
10 use std::os;
11
12 struct Test { x: isize }
13
14 impl Test {
15     fn get_x(&self) -> Option<Box<isize>> {
16         Some(box self.x)
17     }
18 }
19
20 fn do_something(t: &Test) -> isize {
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
34 pub fn main() {
35     let t = Test { x: 1 };
36     do_something(&t);
37 }