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.
4 // The exact error prevented here is:
6 // error[E0382]: use of collaterally moved value: `(root.boxed.rhs as SomeVariant::B).0`
7 // --> src/main.rs:55:29
9 // 56 | lhs: SomeVariant::A(a),
10 // | - value moved here
11 // 57 | rhs: SomeVariant::B(b),
12 // | ^ value used here after move
14 // = note: move occurs because the value has type `A`, which does not implement the `Copy` trait
18 #![feature(box_patterns)]
21 boxed: Box<SetOfVariants>,
24 struct SetOfVariants {
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"))),
44 if let box SetOfVariants {
45 lhs: SomeVariant::A(a),
46 rhs: SomeVariant::B(b),
49 println!("a = {}", a.0);
50 println!("b = {}", b.0);