Skip to content

Commit a4772a4

Browse files
committed
Add test for the known case that doesn't work
1 parent 5d31e29 commit a4772a4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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`.

0 commit comments

Comments
 (0)