Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice patterns: harden match-based borrowck tests #67990

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/test/ui/borrowck/borrowck-move-out-from-array-match.rs
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 src/test/ui/borrowck/borrowck-move-out-from-array-match.stderr
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 src/test/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs
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() {}
Loading