Skip to content

Commit 6fa8f4a

Browse files
committed
bindings_after_at: harden tests wrt. contexts & slice_patterns
1 parent 0034e61 commit 6fa8f4a

14 files changed

+477
-108
lines changed

src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(bindings_after_at)]
44
//~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash
5+
#![feature(slice_patterns)]
56

67
fn main() {
78
struct U; // Not copy!
@@ -28,4 +29,20 @@ fn main() {
2829
//~| ERROR cannot bind by-move with sub-bindings
2930
//~| ERROR use of moved value
3031
}
32+
33+
fn fun(a @ b: U) {}
34+
//~^ ERROR cannot bind by-move with sub-bindings
35+
//~| ERROR use of moved value
36+
37+
match [u(), u(), u(), u()] {
38+
xs @ [a, .., b] => {}
39+
//~^ ERROR cannot bind by-move with sub-bindings
40+
//~| ERROR use of moved value
41+
}
42+
43+
match [u(), u(), u(), u()] {
44+
xs @ [_, ys @ .., _] => {}
45+
//~^ ERROR cannot bind by-move with sub-bindings
46+
//~| ERROR use of moved value
47+
}
3148
}

src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,55 @@ LL | #![feature(bindings_after_at)]
77
= note: `#[warn(incomplete_features)]` on by default
88

99
error[E0007]: cannot bind by-move with sub-bindings
10-
--> $DIR/borrowck-move-and-move.rs:12:9
10+
--> $DIR/borrowck-move-and-move.rs:13:9
1111
|
1212
LL | let a @ b = U;
1313
| ^^^^^ binds an already bound by-move value by moving it
1414

1515
error[E0007]: cannot bind by-move with sub-bindings
16-
--> $DIR/borrowck-move-and-move.rs:16:9
16+
--> $DIR/borrowck-move-and-move.rs:17:9
1717
|
1818
LL | let a @ (b, c) = (U, U);
1919
| ^^^^^^^^^^ binds an already bound by-move value by moving it
2020

2121
error[E0007]: cannot bind by-move with sub-bindings
22-
--> $DIR/borrowck-move-and-move.rs:20:9
22+
--> $DIR/borrowck-move-and-move.rs:21:9
2323
|
2424
LL | let a @ (b, c) = (u(), u());
2525
| ^^^^^^^^^^ binds an already bound by-move value by moving it
2626

2727
error[E0007]: cannot bind by-move with sub-bindings
28-
--> $DIR/borrowck-move-and-move.rs:25:9
28+
--> $DIR/borrowck-move-and-move.rs:26:9
2929
|
3030
LL | a @ Ok(b) | a @ Err(b) => {}
3131
| ^^^^^^^^^ binds an already bound by-move value by moving it
3232

3333
error[E0007]: cannot bind by-move with sub-bindings
34-
--> $DIR/borrowck-move-and-move.rs:25:21
34+
--> $DIR/borrowck-move-and-move.rs:26:21
3535
|
3636
LL | a @ Ok(b) | a @ Err(b) => {}
3737
| ^^^^^^^^^^ binds an already bound by-move value by moving it
3838

39+
error[E0007]: cannot bind by-move with sub-bindings
40+
--> $DIR/borrowck-move-and-move.rs:38:9
41+
|
42+
LL | xs @ [a, .., b] => {}
43+
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
44+
45+
error[E0007]: cannot bind by-move with sub-bindings
46+
--> $DIR/borrowck-move-and-move.rs:44:9
47+
|
48+
LL | xs @ [_, ys @ .., _] => {}
49+
| ^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
50+
51+
error[E0007]: cannot bind by-move with sub-bindings
52+
--> $DIR/borrowck-move-and-move.rs:33:12
53+
|
54+
LL | fn fun(a @ b: U) {}
55+
| ^^^^^ binds an already bound by-move value by moving it
56+
3957
error[E0382]: use of moved value
40-
--> $DIR/borrowck-move-and-move.rs:12:13
58+
--> $DIR/borrowck-move-and-move.rs:13:13
4159
|
4260
LL | let a @ b = U;
4361
| ----^ - move occurs because value has type `main::U`, which does not implement the `Copy` trait
@@ -46,7 +64,7 @@ LL | let a @ b = U;
4664
| value moved here
4765

4866
error[E0382]: use of moved value
49-
--> $DIR/borrowck-move-and-move.rs:16:17
67+
--> $DIR/borrowck-move-and-move.rs:17:17
5068
|
5169
LL | let a @ (b, c) = (U, U);
5270
| --------^- ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
@@ -55,7 +73,7 @@ LL | let a @ (b, c) = (U, U);
5573
| value moved here
5674

5775
error[E0382]: use of moved value
58-
--> $DIR/borrowck-move-and-move.rs:20:17
76+
--> $DIR/borrowck-move-and-move.rs:21:17
5977
|
6078
LL | let a @ (b, c) = (u(), u());
6179
| --------^- ---------- move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
@@ -64,7 +82,7 @@ LL | let a @ (b, c) = (u(), u());
6482
| value moved here
6583

6684
error[E0382]: use of moved value
67-
--> $DIR/borrowck-move-and-move.rs:25:16
85+
--> $DIR/borrowck-move-and-move.rs:26:16
6886
|
6987
LL | match Ok(U) {
7088
| ----- move occurs because value has type `std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
@@ -75,7 +93,7 @@ LL | a @ Ok(b) | a @ Err(b) => {}
7593
| value moved here
7694

7795
error[E0382]: use of moved value
78-
--> $DIR/borrowck-move-and-move.rs:25:29
96+
--> $DIR/borrowck-move-and-move.rs:26:29
7997
|
8098
LL | match Ok(U) {
8199
| ----- move occurs because value has type `std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
@@ -85,7 +103,39 @@ LL | a @ Ok(b) | a @ Err(b) => {}
85103
| | value used here after move
86104
| value moved here
87105

88-
error: aborting due to 10 previous errors
106+
error[E0382]: use of moved value
107+
--> $DIR/borrowck-move-and-move.rs:38:22
108+
|
109+
LL | match [u(), u(), u(), u()] {
110+
| -------------------- move occurs because value has type `[main::U; 4]`, which does not implement the `Copy` trait
111+
LL | xs @ [a, .., b] => {}
112+
| -------------^-
113+
| | |
114+
| | value used here after move
115+
| value moved here
116+
117+
error[E0382]: use of moved value
118+
--> $DIR/borrowck-move-and-move.rs:44:18
119+
|
120+
LL | match [u(), u(), u(), u()] {
121+
| -------------------- move occurs because value has type `[main::U; 4]`, which does not implement the `Copy` trait
122+
LL | xs @ [_, ys @ .., _] => {}
123+
| ---------^^^^^^^----
124+
| | |
125+
| | value used here after move
126+
| value moved here
127+
128+
error[E0382]: use of moved value
129+
--> $DIR/borrowck-move-and-move.rs:33:16
130+
|
131+
LL | fn fun(a @ b: U) {}
132+
| ----^
133+
| | |
134+
| | value used here after move
135+
| value moved here
136+
| move occurs because value has type `main::U`, which does not implement the `Copy` trait
137+
138+
error: aborting due to 16 previous errors
89139

90140
Some errors have detailed explanations: E0007, E0382.
91141
For more information about an error, try `rustc --explain E0007`.

src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ struct C;
99

1010
fn c() -> C { C }
1111

12+
struct NC;
13+
14+
fn nc() -> NC { NC }
15+
1216
fn main() {
1317
let a @ box &b = Box::new(&C);
1418
//~^ ERROR cannot bind by-move with sub-bindings
@@ -18,6 +22,18 @@ fn main() {
1822
//~^ ERROR cannot bind by-move with sub-bindings
1923
//~| ERROR use of moved value
2024

25+
fn f1(a @ box &b: Box<&C>) {}
26+
//~^ ERROR cannot bind by-move with sub-bindings
27+
//~| ERROR use of moved value
28+
29+
fn f2(a @ box b: Box<C>) {}
30+
//~^ ERROR cannot bind by-move with sub-bindings
31+
//~| ERROR use of moved value
32+
33+
match Box::new(C) { a @ box b => {} }
34+
//~^ ERROR cannot bind by-move with sub-bindings
35+
//~| ERROR use of moved value
36+
2137
let ref a @ box b = Box::new(C); // OK; the type is `Copy`.
2238
drop(b);
2339
drop(b);
@@ -28,16 +44,37 @@ fn main() {
2844
drop(b);
2945
drop(a);
3046

31-
struct NC;
32-
33-
fn nc() -> NC { NC }
47+
fn f3(ref a @ box b: Box<C>) { // OK; the type is `Copy`.
48+
drop(b);
49+
drop(b);
50+
drop(a);
51+
}
52+
match Box::new(c()) {
53+
ref a @ box b => { // OK; the type is `Copy`.
54+
drop(b);
55+
drop(b);
56+
drop(a);
57+
}
58+
}
3459

3560
let ref a @ box b = Box::new(NC); //~ ERROR cannot bind by-move and by-ref in the same pattern
3661

3762
let ref a @ box ref b = Box::new(NC); // OK.
3863
drop(a);
3964
drop(b);
4065

66+
fn f4(ref a @ box ref b: Box<NC>) { // OK.
67+
drop(a);
68+
drop(b)
69+
}
70+
71+
match Box::new(nc()) {
72+
ref a @ box ref b => { // OK.
73+
drop(a);
74+
drop(b);
75+
}
76+
}
77+
4178
let ref a @ box ref mut b = Box::new(nc());
4279
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
4380
let ref a @ box ref mut b = Box::new(NC);
@@ -56,4 +93,20 @@ fn main() {
5693
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
5794
*a = Box::new(NC);
5895
drop(b);
96+
97+
fn f5(ref mut a @ box ref b: Box<NC>) {
98+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
99+
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
100+
*a = Box::new(NC);
101+
drop(b);
102+
}
103+
104+
match Box::new(nc()) {
105+
ref mut a @ box ref b => {
106+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
107+
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
108+
*a = Box::new(NC);
109+
drop(b);
110+
}
111+
}
59112
}

0 commit comments

Comments
 (0)