]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-19367.rs
rollup merge of #19589: huonw/unboxed-closure-elision
[rust.git] / src / test / run-pass / issue-19367.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(tuple_indexing)]
12 struct S {
13     o: Option<String>
14 }
15
16 // Make sure we don't reuse the same alloca when matching
17 // on field of struct or tuple which we reassign in the match body.
18
19 fn main() {
20     let mut a = (0i, Some("right".into_string()));
21     let b = match a.1 {
22         Some(v) => {
23             a.1 = Some("wrong".into_string());
24             v
25         }
26         None => String::new()
27     };
28     println!("{}", b);
29     assert_eq!(b, "right");
30
31
32     let mut s = S{ o: Some("right".into_string()) };
33     let b = match s.o {
34         Some(v) => {
35             s.o = Some("wrong".into_string());
36             v
37         }
38         None => String::new(),
39     };
40     println!("{}", b);
41     assert_eq!(b, "right");
42 }