File tree 2 files changed +49
-0
lines changed
tests/ui/pattern/bindings-after-at
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ //@ known-bug: unknown
2
+ #![ allow( unused) ]
3
+
4
+ struct A ( u32 ) ;
5
+
6
+ pub fn main ( ) {
7
+ // The or-pattern bindings are lowered after `x`, which triggers the error.
8
+ let x @ ( A ( a) | A ( a) ) = A ( 10 ) ;
9
+ //~^ ERROR: use of moved value
10
+ //~| ERROR: use of moved value
11
+ assert ! ( x. 0 == 10 ) ;
12
+ assert ! ( a == 10 ) ;
13
+
14
+ // This works.
15
+ let ( x @ A ( a) | x @ A ( a) ) = A ( 10 ) ;
16
+ assert ! ( x. 0 == 10 ) ;
17
+ assert ! ( a == 10 ) ;
18
+ }
Original file line number Diff line number Diff line change
1
+ error[E0382]: use of moved value
2
+ --> $DIR/bind-by-copy-or-pat.rs:7:16
3
+ |
4
+ LL | let x @ (A(a) | A(a)) = A(10);
5
+ | - ^ ----- move occurs because value has type `A`, which does not implement the `Copy` trait
6
+ | | |
7
+ | | value used here after move
8
+ | value moved here
9
+ |
10
+ help: borrow this binding in the pattern to avoid moving the value
11
+ |
12
+ LL | let ref x @ (A(a) | A(a)) = A(10);
13
+ | +++
14
+
15
+ error[E0382]: use of moved value
16
+ --> $DIR/bind-by-copy-or-pat.rs:7:23
17
+ |
18
+ LL | let x @ (A(a) | A(a)) = A(10);
19
+ | - ^ ----- move occurs because value has type `A`, which does not implement the `Copy` trait
20
+ | | |
21
+ | | value used here after move
22
+ | value moved here
23
+ |
24
+ help: borrow this binding in the pattern to avoid moving the value
25
+ |
26
+ LL | let ref x @ (A(a) | A(a)) = A(10);
27
+ | +++
28
+
29
+ error: aborting due to 2 previous errors
30
+
31
+ For more information about this error, try `rustc --explain E0382`.
You can’t perform that action at this time.
0 commit comments