Skip to content

Commit 427b1c3

Browse files
committed
clarify bind-by-move-neither-can-livee..
1 parent 6fa8f4a commit 427b1c3

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This test is taken directly from #16053.
2+
// It checks that you cannot use an AND-pattern (`binding @ pat`)
3+
// where one side is by-ref and the other is by-move.
4+
15
#![feature(bindings_after_at)]
26
//~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash
37

@@ -9,4 +13,24 @@ fn main() {
913
Some(ref _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
1014
None => panic!()
1115
}
16+
17+
let x = Some(X { x: () });
18+
match x {
19+
Some(_z @ ref _y) => { }, //~ ERROR cannot bind by-move with sub-bindings
20+
//~^ ERROR borrow of moved value
21+
None => panic!()
22+
}
23+
24+
let mut x = Some(X { x: () });
25+
match x {
26+
Some(ref mut _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
27+
None => panic!()
28+
}
29+
30+
let mut x = Some(X { x: () });
31+
match x {
32+
Some(_z @ ref mut _y) => { }, //~ ERROR cannot bind by-move with sub-bindings
33+
//~^ ERROR borrow of moved value
34+
None => panic!()
35+
}
1236
}
Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,64 @@
11
warning: the feature `bindings_after_at` is incomplete and may cause the compiler to crash
2-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:1:12
2+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:5:12
33
|
44
LL | #![feature(bindings_after_at)]
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

99
error[E0009]: cannot bind by-move and by-ref in the same pattern
10-
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:9:23
10+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:13:23
1111
|
1212
LL | Some(ref _y @ _z) => { },
1313
| ---------^^
1414
| | |
1515
| | by-move pattern here
1616
| by-ref pattern here
1717

18-
error: aborting due to previous error
18+
error[E0007]: cannot bind by-move with sub-bindings
19+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:19:14
20+
|
21+
LL | Some(_z @ ref _y) => { },
22+
| ^^^^^^^^^^^ binds an already bound by-move value by moving it
23+
24+
error[E0009]: cannot bind by-move and by-ref in the same pattern
25+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:26:27
26+
|
27+
LL | Some(ref mut _y @ _z) => { },
28+
| -------------^^
29+
| | |
30+
| | by-move pattern here
31+
| by-ref pattern here
32+
33+
error[E0007]: cannot bind by-move with sub-bindings
34+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:32:14
35+
|
36+
LL | Some(_z @ ref mut _y) => { },
37+
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
38+
39+
error[E0382]: borrow of moved value
40+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:19:19
41+
|
42+
LL | Some(_z @ ref _y) => { },
43+
| -----^^^^^^
44+
| | |
45+
| | value borrowed here after move
46+
| value moved here
47+
|
48+
= note: move occurs because value has type `X`, which does not implement the `Copy` trait
49+
50+
error[E0382]: borrow of moved value
51+
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:32:19
52+
|
53+
LL | Some(_z @ ref mut _y) => { },
54+
| -----^^^^^^^^^^
55+
| | |
56+
| | value borrowed here after move
57+
| value moved here
58+
|
59+
= note: move occurs because value has type `X`, which does not implement the `Copy` trait
60+
61+
error: aborting due to 6 previous errors
1962

20-
For more information about this error, try `rustc --explain E0009`.
63+
Some errors have detailed explanations: E0007, E0009, E0382.
64+
For more information about an error, try `rustc --explain E0007`.

0 commit comments

Comments
 (0)