Skip to content

Commit

Permalink
Rollup merge of rust-lang#67990 - Centril:slice-pats-move-tests-match…
Browse files Browse the repository at this point in the history
…, r=matthewjasper

slice patterns: harden match-based borrowck tests

This hardens some move-checking tests wrt. slice patterns and `match` expressions.

r? @matthewjasper
cc @pnkfelix
cc rust-lang#67712
cc rust-lang#53114
  • Loading branch information
Centril authored Jan 8, 2020
2 parents ea9a03d + 0a6cdc2 commit 916a7d3
Show file tree
Hide file tree
Showing 8 changed files with 978 additions and 0 deletions.
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

0 comments on commit 916a7d3

Please sign in to comment.