]> git.lizzy.rs Git - rust.git/blob - tests/ui/by-move-pattern-binding.rs
Rollup merge of #107576 - P1n3appl3:master, r=tmandry
[rust.git] / tests / ui / by-move-pattern-binding.rs
1 enum E {
2     Foo,
3     Bar(String)
4 }
5
6 struct S {
7     x: E
8 }
9
10 fn f(x: String) {}
11
12 fn main() {
13     let s = S { x: E::Bar("hello".to_string()) };
14     match &s.x { //~ ERROR cannot move
15         &E::Foo => {}
16         &E::Bar(identifier) => f(identifier.clone())
17     };
18     match &s.x {
19         &E::Foo => {}
20         &E::Bar(ref identifier) => println!("{}", *identifier)
21     };
22     if let &E::Bar(identifier) = &s.x { //~ ERROR cannot move
23         f(identifier.clone());
24     };
25     let &E::Bar(identifier) = &s.x else { //~ ERROR cannot move
26         return;
27     };
28     f(identifier.clone());
29 }