-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slice patterns: harden match-based borrowck tests
- Loading branch information
Showing
8 changed files
with
978 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
src/test/ui/borrowck/borrowck-move-out-from-array-match.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#![feature(slice_patterns)] | ||
|
||
fn array() -> [(String, String); 3] { | ||
Default::default() | ||
} | ||
|
||
// Const Index + Const Index | ||
|
||
fn move_out_from_begin_and_end() { | ||
let a = array(); | ||
match a { | ||
[_, _, _x] => {} | ||
} | ||
match a { | ||
[.., _y] => {} //~ ERROR use of moved value | ||
} | ||
} | ||
|
||
fn move_out_from_begin_field_and_end() { | ||
let a = array(); | ||
match a { | ||
[_, _, (_x, _)] => {} | ||
} | ||
match a { | ||
[.., _y] => {} //~ ERROR use of moved value | ||
} | ||
} | ||
|
||
fn move_out_from_begin_field_and_end_field() { | ||
let a = array(); | ||
match a { | ||
[_, _, (_x, _)] => {} | ||
} | ||
match a { | ||
[.., (_y, _)] => {} //~ ERROR use of moved value | ||
} | ||
} | ||
|
||
// Const Index + Slice | ||
|
||
fn move_out_by_const_index_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[_x, _, _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_y @ .., _, _] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_end_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[.., _x] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_field_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[(_x, _), _, _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_y @ .., _, _] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_end_field_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[.., (_x, _)] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_subslice_and_const_index_field() { | ||
let a = array(); | ||
match a { | ||
[_y @ .., _, _] => {} | ||
} | ||
match a { | ||
[(_x, _), _, _] => {} //~ ERROR use of moved value | ||
} | ||
} | ||
|
||
fn move_out_by_subslice_and_const_index_end_field() { | ||
let a = array(); | ||
match a { | ||
[_, _, _y @ ..] => {} | ||
} | ||
match a { | ||
[.., (_x, _)] => {} //~ ERROR use of moved value | ||
} | ||
} | ||
|
||
// Slice + Slice | ||
|
||
fn move_out_by_subslice_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[x @ .., _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn main() {} |
113 changes: 113 additions & 0 deletions
113
src/test/ui/borrowck/borrowck-move-out-from-array-match.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
error[E0382]: use of moved value: `a[..]` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:15:14 | ||
| | ||
LL | [_, _, _x] => {} | ||
| -- value moved here | ||
... | ||
LL | [.., _y] => {} | ||
| ^^ value used here after move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a[..]` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:25:14 | ||
| | ||
LL | [_, _, (_x, _)] => {} | ||
| -- value moved here | ||
... | ||
LL | [.., _y] => {} | ||
| ^^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a[..].0` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:35:15 | ||
| | ||
LL | [_, _, (_x, _)] => {} | ||
| -- value moved here | ||
... | ||
LL | [.., (_y, _)] => {} | ||
| ^^ value used here after move | ||
| | ||
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:46:11 | ||
| | ||
LL | [_x, _, _] => {} | ||
| -- value moved here | ||
LL | } | ||
LL | match a { | ||
| ^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:57:11 | ||
| | ||
LL | [.., _x] => {} | ||
| -- value moved here | ||
LL | } | ||
LL | match a { | ||
| ^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:68:11 | ||
| | ||
LL | [(_x, _), _, _] => {} | ||
| -- value moved here | ||
LL | } | ||
LL | match a { | ||
| ^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:79:11 | ||
| | ||
LL | [.., (_x, _)] => {} | ||
| -- value moved here | ||
LL | } | ||
LL | match a { | ||
| ^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a[..].0` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:91:11 | ||
| | ||
LL | [_y @ .., _, _] => {} | ||
| ------- value moved here | ||
... | ||
LL | [(_x, _), _, _] => {} | ||
| ^^ value used here after move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a[..].0` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:101:15 | ||
| | ||
LL | [_, _, _y @ ..] => {} | ||
| ------- value moved here | ||
... | ||
LL | [.., (_x, _)] => {} | ||
| ^^ value used here after move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/borrowck-move-out-from-array-match.rs:112:11 | ||
| | ||
LL | [x @ .., _] => {} | ||
| ------ value moved here | ||
LL | } | ||
LL | match a { | ||
| ^ value used here after partial move | ||
| | ||
= note: move occurs because `a[..]` has type `(std::string::String, std::string::String)`, which does not implement the `Copy` trait | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
117 changes: 117 additions & 0 deletions
117
src/test/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Due to #53114, which causes a "read" of the `_` patterns, | ||
// the borrow-checker refuses this code, while it should probably be allowed. | ||
// Once the bug is fixed, the test, which is derived from a | ||
// passing test for `let` statements, should become check-pass. | ||
|
||
#![feature(slice_patterns)] | ||
|
||
fn array() -> [(String, String); 3] { | ||
Default::default() | ||
} | ||
|
||
// Const Index + Const Index | ||
|
||
fn move_out_from_begin_and_one_from_end() { | ||
let a = array(); | ||
match a { | ||
[_, _, _x] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[.., _y, _] => {} | ||
} | ||
} | ||
|
||
fn move_out_from_begin_field_and_end_field() { | ||
let a = array(); | ||
match a { | ||
[_, _, (_x, _)] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[.., (_, _y)] => {} | ||
} | ||
} | ||
|
||
// Const Index + Slice | ||
|
||
fn move_out_by_const_index_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[_x, _, _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_end_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[.., _x] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_y @ .., _] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_field_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[(_x, _), _, _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_index_end_field_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[.., (_x, _)] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_y @ .., _] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_subslice_and_index_field() { | ||
let a = array(); | ||
match a { | ||
[_, _y @ ..] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[(_x, _), _, _] => {} | ||
} | ||
} | ||
|
||
fn move_out_by_const_subslice_and_end_index_field() { | ||
let a = array(); | ||
match a { | ||
[_y @ .., _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[.., (_x, _)] => {} | ||
} | ||
} | ||
|
||
// Slice + Slice | ||
|
||
fn move_out_by_subslice_and_subslice() { | ||
let a = array(); | ||
match a { | ||
[x @ .., _, _] => {} | ||
} | ||
match a { | ||
//~^ ERROR use of moved value | ||
[_, _y @ ..] => {} | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.