]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-19367.rs
Rollup merge of #100168 - WaffleLapkin:improve_diagnostics_for_missing_type_in_a_cons...
[rust.git] / src / test / ui / issues / issue-19367.rs
1 // run-pass
2 struct S {
3     o: Option<String>
4 }
5
6 // Make sure we don't reuse the same alloca when matching
7 // on field of struct or tuple which we reassign in the match body.
8
9 fn main() {
10     let mut a = (0, Some("right".to_string()));
11     let b = match a.1 {
12         Some(v) => {
13             a.1 = Some("wrong".to_string());
14             v
15         }
16         None => String::new()
17     };
18     println!("{}", b);
19     assert_eq!(b, "right");
20
21
22     let mut s = S{ o: Some("right".to_string()) };
23     let b = match s.o {
24         Some(v) => {
25             s.o = Some("wrong".to_string());
26             v
27         }
28         None => String::new(),
29     };
30     println!("{}", b);
31     assert_eq!(b, "right");
32 }