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