2019-07-27 00:54:25 +03:00
|
|
|
//@ run-pass
|
|
|
|
|
2018-09-14 12:20:28 +02:00
|
|
|
#![allow(stable_features)]
|
|
|
|
#![allow(unused_imports)]
|
2014-01-15 14:39:08 -05:00
|
|
|
// Test that cleanup scope for temporaries created in a match
|
|
|
|
// arm is confined to the match arm itself.
|
|
|
|
|
2015-03-22 13:13:15 -07:00
|
|
|
//@ pretty-expanded FIXME #23616
|
|
|
|
|
2021-08-25 02:39:40 +02:00
|
|
|
#![feature(os)]
|
2015-01-08 02:25:56 +01:00
|
|
|
|
2014-02-18 12:04:51 -08:00
|
|
|
use std::os;
|
2014-01-15 14:39:08 -05:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
struct Test { x: isize }
|
2014-01-15 14:39:08 -05:00
|
|
|
|
|
|
|
impl Test {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn get_x(&self) -> Option<Box<isize>> {
|
2021-08-25 02:39:40 +02:00
|
|
|
Some(Box::new(self.x))
|
2014-01-15 14:39:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn do_something(t: &Test) -> isize {
|
2014-01-15 14:39:08 -05:00
|
|
|
|
|
|
|
// The cleanup scope for the result of `t.get_x()` should be the
|
|
|
|
// arm itself and not the match, otherwise we'll (potentially) get
|
|
|
|
// a crash trying to free an uninitialized stack slot.
|
|
|
|
|
|
|
|
match t {
|
|
|
|
&Test { x: 2 } if t.get_x().is_some() => {
|
|
|
|
t.x * 2
|
|
|
|
}
|
|
|
|
_ => { 22 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let t = Test { x: 1 };
|
|
|
|
do_something(&t);
|
|
|
|
}
|