Skip to content

Commit 0a6cdc2

Browse files
committed
slice patterns: harden match-based borrowck tests
1 parent 8597644 commit 0a6cdc2

8 files changed

+978
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#![feature(slice_patterns)]
2+
3+
fn array() -> [(String, String); 3] {
4+
Default::default()
5+
}
6+
7+
// Const Index + Const Index
8+
9+
fn move_out_from_begin_and_end() {
10+
let a = array();
11+
match a {
12+
[_, _, _x] => {}
13+
}
14+
match a {
15+
[.., _y] => {} //~ ERROR use of moved value
16+
}
17+
}
18+
19+
fn move_out_from_begin_field_and_end() {
20+
let a = array();
21+
match a {
22+
[_, _, (_x, _)] => {}
23+
}
24+
match a {
25+
[.., _y] => {} //~ ERROR use of moved value
26+
}
27+
}
28+
29+
fn move_out_from_begin_field_and_end_field() {
30+
let a = array();
31+
match a {
32+
[_, _, (_x, _)] => {}
33+
}
34+
match a {
35+
[.., (_y, _)] => {} //~ ERROR use of moved value
36+
}
37+
}
38+
39+
// Const Index + Slice
40+
41+
fn move_out_by_const_index_and_subslice() {
42+
let a = array();
43+
match a {
44+
[_x, _, _] => {}
45+
}
46+
match a {
47+
//~^ ERROR use of moved value
48+
[_y @ .., _, _] => {}
49+
}
50+
}
51+
52+
fn move_out_by_const_index_end_and_subslice() {
53+
let a = array();
54+
match a {
55+
[.., _x] => {}
56+
}
57+
match a {
58+
//~^ ERROR use of moved value
59+
[_, _, _y @ ..] => {}
60+
}
61+
}
62+
63+
fn move_out_by_const_index_field_and_subslice() {
64+
let a = array();
65+
match a {
66+
[(_x, _), _, _] => {}
67+
}
68+
match a {
69+
//~^ ERROR use of moved value
70+
[_y @ .., _, _] => {}
71+
}
72+
}
73+
74+
fn move_out_by_const_index_end_field_and_subslice() {
75+
let a = array();
76+
match a {
77+
[.., (_x, _)] => {}
78+
}
79+
match a {
80+
//~^ ERROR use of moved value
81+
[_, _, _y @ ..] => {}
82+
}
83+
}
84+
85+
fn move_out_by_subslice_and_const_index_field() {
86+
let a = array();
87+
match a {
88+
[_y @ .., _, _] => {}
89+
}
90+
match a {
91+
[(_x, _), _, _] => {} //~ ERROR use of moved value
92+
}
93+
}
94+
95+
fn move_out_by_subslice_and_const_index_end_field() {
96+
let a = array();
97+
match a {
98+
[_, _, _y @ ..] => {}
99+
}
100+
match a {
101+
[.., (_x, _)] => {} //~ ERROR use of moved value
102+
}
103+
}
104+
105+
// Slice + Slice
106+
107+
fn move_out_by_subslice_and_subslice() {
108+
let a = array();
109+
match a {
110+
[x @ .., _] => {}
111+
}
112+
match a {
113+
//~^ ERROR use of moved value
114+
[_, _y @ ..] => {}
115+
}
116+
}
117+
118+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
error[E0382]: use of moved value: `a[..]`
2+
--> $DIR/borrowck-move-out-from-array-match.rs:15:14
3+
|
4+
LL | [_, _, _x] => {}
5+
| -- value moved here
6+
...
7+
LL | [.., _y] => {}
8+
| ^^ value used here after move
9+
|
10+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
11+
12+
error[E0382]: use of moved value: `a[..]`
13+
--> $DIR/borrowck-move-out-from-array-match.rs:25:14
14+
|
15+
LL | [_, _, (_x, _)] => {}
16+
| -- value moved here
17+
...
18+
LL | [.., _y] => {}
19+
| ^^ value used here after partial move
20+
|
21+
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
22+
23+
error[E0382]: use of moved value: `a[..].0`
24+
--> $DIR/borrowck-move-out-from-array-match.rs:35:15
25+
|
26+
LL | [_, _, (_x, _)] => {}
27+
| -- value moved here
28+
...
29+
LL | [.., (_y, _)] => {}
30+
| ^^ value used here after move
31+
|
32+
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
33+
34+
error[E0382]: use of moved value: `a`
35+
--> $DIR/borrowck-move-out-from-array-match.rs:46:11
36+
|
37+
LL | [_x, _, _] => {}
38+
| -- value moved here
39+
LL | }
40+
LL | match a {
41+
| ^ value used here after partial move
42+
|
43+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
44+
45+
error[E0382]: use of moved value: `a`
46+
--> $DIR/borrowck-move-out-from-array-match.rs:57:11
47+
|
48+
LL | [.., _x] => {}
49+
| -- value moved here
50+
LL | }
51+
LL | match a {
52+
| ^ value used here after partial move
53+
|
54+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
55+
56+
error[E0382]: use of moved value: `a`
57+
--> $DIR/borrowck-move-out-from-array-match.rs:68:11
58+
|
59+
LL | [(_x, _), _, _] => {}
60+
| -- value moved here
61+
LL | }
62+
LL | match a {
63+
| ^ value used here after partial move
64+
|
65+
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
66+
67+
error[E0382]: use of moved value: `a`
68+
--> $DIR/borrowck-move-out-from-array-match.rs:79:11
69+
|
70+
LL | [.., (_x, _)] => {}
71+
| -- value moved here
72+
LL | }
73+
LL | match a {
74+
| ^ value used here after partial move
75+
|
76+
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait
77+
78+
error[E0382]: use of moved value: `a[..].0`
79+
--> $DIR/borrowck-move-out-from-array-match.rs:91:11
80+
|
81+
LL | [_y @ .., _, _] => {}
82+
| ------- value moved here
83+
...
84+
LL | [(_x, _), _, _] => {}
85+
| ^^ value used here after move
86+
|
87+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
88+
89+
error[E0382]: use of moved value: `a[..].0`
90+
--> $DIR/borrowck-move-out-from-array-match.rs:101:15
91+
|
92+
LL | [_, _, _y @ ..] => {}
93+
| ------- value moved here
94+
...
95+
LL | [.., (_x, _)] => {}
96+
| ^^ value used here after move
97+
|
98+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
99+
100+
error[E0382]: use of moved value: `a`
101+
--> $DIR/borrowck-move-out-from-array-match.rs:112:11
102+
|
103+
LL | [x @ .., _] => {}
104+
| ------ value moved here
105+
LL | }
106+
LL | match a {
107+
| ^ value used here after partial move
108+
|
109+
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait
110+
111+
error: aborting due to 10 previous errors
112+
113+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Due to #53114, which causes a "read" of the `_` patterns,
2+
// the borrow-checker refuses this code, while it should probably be allowed.
3+
// Once the bug is fixed, the test, which is derived from a
4+
// passing test for `let` statements, should become check-pass.
5+
6+
#![feature(slice_patterns)]
7+
8+
fn array() -> [(String, String); 3] {
9+
Default::default()
10+
}
11+
12+
// Const Index + Const Index
13+
14+
fn move_out_from_begin_and_one_from_end() {
15+
let a = array();
16+
match a {
17+
[_, _, _x] => {}
18+
}
19+
match a {
20+
//~^ ERROR use of moved value
21+
[.., _y, _] => {}
22+
}
23+
}
24+
25+
fn move_out_from_begin_field_and_end_field() {
26+
let a = array();
27+
match a {
28+
[_, _, (_x, _)] => {}
29+
}
30+
match a {
31+
//~^ ERROR use of moved value
32+
[.., (_, _y)] => {}
33+
}
34+
}
35+
36+
// Const Index + Slice
37+
38+
fn move_out_by_const_index_and_subslice() {
39+
let a = array();
40+
match a {
41+
[_x, _, _] => {}
42+
}
43+
match a {
44+
//~^ ERROR use of moved value
45+
[_, _y @ ..] => {}
46+
}
47+
}
48+
49+
fn move_out_by_const_index_end_and_subslice() {
50+
let a = array();
51+
match a {
52+
[.., _x] => {}
53+
}
54+
match a {
55+
//~^ ERROR use of moved value
56+
[_y @ .., _] => {}
57+
}
58+
}
59+
60+
fn move_out_by_const_index_field_and_subslice() {
61+
let a = array();
62+
match a {
63+
[(_x, _), _, _] => {}
64+
}
65+
match a {
66+
//~^ ERROR use of moved value
67+
[_, _y @ ..] => {}
68+
}
69+
}
70+
71+
fn move_out_by_const_index_end_field_and_subslice() {
72+
let a = array();
73+
match a {
74+
[.., (_x, _)] => {}
75+
}
76+
match a {
77+
//~^ ERROR use of moved value
78+
[_y @ .., _] => {}
79+
}
80+
}
81+
82+
fn move_out_by_const_subslice_and_index_field() {
83+
let a = array();
84+
match a {
85+
[_, _y @ ..] => {}
86+
}
87+
match a {
88+
//~^ ERROR use of moved value
89+
[(_x, _), _, _] => {}
90+
}
91+
}
92+
93+
fn move_out_by_const_subslice_and_end_index_field() {
94+
let a = array();
95+
match a {
96+
[_y @ .., _] => {}
97+
}
98+
match a {
99+
//~^ ERROR use of moved value
100+
[.., (_x, _)] => {}
101+
}
102+
}
103+
104+
// Slice + Slice
105+
106+
fn move_out_by_subslice_and_subslice() {
107+
let a = array();
108+
match a {
109+
[x @ .., _, _] => {}
110+
}
111+
match a {
112+
//~^ ERROR use of moved value
113+
[_, _y @ ..] => {}
114+
}
115+
}
116+
117+
fn main() {}

0 commit comments

Comments
 (0)