]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/issue-16223.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / nll / issue-16223.rs
1 // Regression test for #16223: without NLL the `if let` construct together with
2 // the nested box-structure of `Root` causes an unwanted collateral move.
3
4 // The exact error prevented here is:
5 //
6 // error[E0382]: use of collaterally moved value: `(root.boxed.rhs as SomeVariant::B).0`
7 // --> src/main.rs:55:29
8 // |
9 // 56 | lhs: SomeVariant::A(a),
10 // | - value moved here
11 // 57 | rhs: SomeVariant::B(b),
12 // | ^ value used here after move
13 // |
14 // = note: move occurs because the value has type `A`, which does not implement the `Copy` trait
15
16 // check-pass
17
18 #![feature(box_patterns)]
19
20 struct Root {
21 boxed: Box<SetOfVariants>,
22 }
23
24 struct SetOfVariants {
25 lhs: SomeVariant,
26 rhs: SomeVariant,
27 }
28
29 enum SomeVariant {
30 A(A),
31 B(B),
32 }
33
34 struct A(String);
35 struct B(String);
36
37 fn main() {
38 let root = Root {
39 boxed: Box::new(SetOfVariants {
40 lhs: SomeVariant::A(A(String::from("This is A"))),
41 rhs: SomeVariant::B(B(String::from("This is B"))),
42 }),
43 };
44 if let box SetOfVariants {
45 lhs: SomeVariant::A(a),
46 rhs: SomeVariant::B(b),
47 } = root.boxed
48 {
49 println!("a = {}", a.0);
50 println!("b = {}", b.0);
51 }
52 }