Skip to content

Commit

Permalink
Add more tests for borrowck and dropck slice pattern handling
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Dec 9, 2019
1 parent cab7af9 commit d96485d
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 75 deletions.
69 changes: 69 additions & 0 deletions src/test/ui/borrowck/borrowck-move-out-from-array-no-overlap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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();
let [_, _, _x] = a;
let [.., _y, _] = a;
}

fn move_out_from_begin_field_and_end_field() {
let a = array();
let [_, _, (_x, _)] = a;
let [.., (_, _y)] = a;
}

// Const Index + Slice

fn move_out_by_const_index_and_subslice() {
let a = array();
let [_x, _, _] = a;
let [_, _y @ ..] = a;
}

fn move_out_by_const_index_end_and_subslice() {
let a = array();
let [.., _x] = a;
let [_y @ .., _] = a;
}

fn move_out_by_const_index_field_and_subslice() {
let a = array();
let [(_x, _), _, _] = a;
let [_, _y @ ..] = a;
}

fn move_out_by_const_index_end_field_and_subslice() {
let a = array();
let [.., (_x, _)] = a;
let [_y @ .., _] = a;
}

fn move_out_by_const_subslice_and_index_field() {
let a = array();
let [_, _y @ ..] = a;
let [(_x, _), _, _] = a;
}

fn move_out_by_const_subslice_and_end_index_field() {
let a = array();
let [_y @ .., _] = a;
let [.., (_x, _)] = a;
}

// Slice + Slice

fn move_out_by_subslice_and_subslice() {
let a = array();
let [x @ .., _, _] = a;
let [_, _y @ ..] = a;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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();
let [_, _, _x] = a;
let [.., ref _y, _] = a;
}

fn move_out_from_begin_field_and_end_field() {
let a = array();
let [_, _, (_x, _)] = a;
let [.., (_, ref _y)] = a;
}

// Const Index + Slice

fn move_out_by_const_index_and_subslice() {
let a = array();
let [_x, _, _] = a;
let [_, ref _y @ ..] = a;
}

fn move_out_by_const_index_end_and_subslice() {
let a = array();
let [.., _x] = a;
let [ref _y @ .., _] = a;
}

fn move_out_by_const_index_field_and_subslice() {
let a = array();
let [(_x, _), _, _] = a;
let [_, ref _y @ ..] = a;
}

fn move_out_by_const_index_end_field_and_subslice() {
let a = array();
let [.., (_x, _)] = a;
let [ref _y @ .., _] = a;
}

fn move_out_by_const_subslice_and_index_field() {
let a = array();
let [_, _y @ ..] = a;
let [(ref _x, _), _, _] = a;
}

fn move_out_by_const_subslice_and_end_index_field() {
let a = array();
let [_y @ .., _] = a;
let [.., (ref _x, _)] = a;
}

// Slice + Slice

fn move_out_by_subslice_and_subslice() {
let a = array();
let [x @ .., _, _] = a;
let [_, ref _y @ ..] = a;
}

fn main() {}
99 changes: 99 additions & 0 deletions src/test/ui/borrowck/borrowck-move-out-from-array-use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#![feature(slice_patterns)]

fn array() -> [(String, String); 3] {
Default::default()
}

// Const Index + Const Index

fn move_out_from_begin_and_end() {
let a = array();
let [_, _, _x] = a;
let [.., ref _y] = a; //~ ERROR [E0382]
}

fn move_out_from_begin_field_and_end() {
let a = array();
let [_, _, (_x, _)] = a;
let [.., ref _y] = a; //~ ERROR [E0382]
}

fn move_out_from_begin_field_and_end_field() {
let a = array();
let [_, _, (_x, _)] = a;
let [.., (ref _y, _)] = a; //~ ERROR [E0382]
}

// Const Index + Slice

fn move_out_by_const_index_and_subslice() {
let a = array();
let [_x, _, _] = a;
let [ref _y @ .., _, _] = a; //~ ERROR [E0382]
}

fn move_out_by_const_index_end_and_subslice() {
let a = array();
let [.., _x] = a;
let [_, _, ref _y @ ..] = a; //~ ERROR [E0382]
}

fn move_out_by_const_index_field_and_subslice() {
let a = array();
let [(_x, _), _, _] = a;
let [ref _y @ .., _, _] = a; //~ ERROR [E0382]
}

fn move_out_by_const_index_end_field_and_subslice() {
let a = array();
let [.., (_x, _)] = a;
let [_, _, ref _y @ ..] = a; //~ ERROR [E0382]
}

fn move_out_by_subslice_and_const_index_field() {
let a = array();
let [_y @ .., _, _] = a;
let [(ref _x, _), _, _] = a; //~ ERROR [E0382]
}

fn move_out_by_subslice_and_const_index_end_field() {
let a = array();
let [_, _, _y @ ..] = a;
let [.., (ref _x, _)] = a; //~ ERROR [E0382]
}

// Slice + Slice

fn move_out_by_subslice_and_subslice() {
let a = array();
let [x @ .., _] = a;
let [_, ref _y @ ..] = a; //~ ERROR [E0382]
}

// Move + Assign

fn move_out_and_assign_end() {
let mut a = array();
let [_, _, _x] = a;
a[2] = Default::default(); //~ ERROR [E0382]
}

fn move_out_and_assign_end_field() {
let mut a = array();
let [_, _, (_x, _)] = a;
a[2].1 = Default::default(); //~ ERROR [E0382]
}

fn move_out_slice_and_assign_end() {
let mut a = array();
let [_, _, _x @ ..] = a;
a[0] = Default::default(); //~ ERROR [E0382]
}

fn move_out_slice_and_assign_end_field() {
let mut a = array();
let [_, _, _x @ ..] = a;
a[0].1 = Default::default(); //~ ERROR [E0382]
}

fn main() {}
143 changes: 143 additions & 0 deletions src/test/ui/borrowck/borrowck-move-out-from-array-use.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
error[E0382]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use.rs:12:14
|
LL | let [_, _, _x] = a;
| -- value moved here
LL | let [.., ref _y] = a;
| ^^^^^^ value borrowed 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]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use.rs:18:14
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
LL | let [.., ref _y] = a;
| ^^^^^^ value borrowed here after partial move
|
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value: `a[..].0`
--> $DIR/borrowck-move-out-from-array-use.rs:24:15
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
LL | let [.., (ref _y, _)] = a;
| ^^^^^^ value borrowed here after move
|
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value: `a`
--> $DIR/borrowck-move-out-from-array-use.rs:32:10
|
LL | let [_x, _, _] = a;
| -- value moved here
LL | let [ref _y @ .., _, _] = a;
| ^^^^^^^^^^^ value borrowed 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]: borrow of moved value: `a`
--> $DIR/borrowck-move-out-from-array-use.rs:38:16
|
LL | let [.., _x] = a;
| -- value moved here
LL | let [_, _, ref _y @ ..] = a;
| ^^^^^^^^^^^ value borrowed 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]: borrow of moved value: `a`
--> $DIR/borrowck-move-out-from-array-use.rs:44:10
|
LL | let [(_x, _), _, _] = a;
| -- value moved here
LL | let [ref _y @ .., _, _] = a;
| ^^^^^^^^^^^ value borrowed here after partial move
|
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value: `a`
--> $DIR/borrowck-move-out-from-array-use.rs:50:16
|
LL | let [.., (_x, _)] = a;
| -- value moved here
LL | let [_, _, ref _y @ ..] = a;
| ^^^^^^^^^^^ value borrowed here after partial move
|
= note: move occurs because `a[..].0` has type `std::string::String`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use.rs:56:11
|
LL | let [_y @ .., _, _] = a;
| ------- value moved here
LL | let [(ref _x, _), _, _] = a;
| ^^^^^^ value borrowed 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]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use.rs:62:15
|
LL | let [_, _, _y @ ..] = a;
| ------- value moved here
LL | let [.., (ref _x, _)] = a;
| ^^^^^^ value borrowed 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]: borrow of moved value: `a`
--> $DIR/borrowck-move-out-from-array-use.rs:70:13
|
LL | let [x @ .., _] = a;
| ------ value moved here
LL | let [_, ref _y @ ..] = a;
| ^^^^^^^^^^^ value borrowed 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-use.rs:78:5
|
LL | let [_, _, _x] = a;
| -- value moved here
LL | a[2] = Default::default();
| ^^^^ 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-use.rs:84:5
|
LL | let [_, _, (_x, _)] = a;
| -- value moved here
LL | a[2].1 = Default::default();
| ^^^^ 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-use.rs:90:5
|
LL | let [_, _, _x @ ..] = a;
| ------- value moved here
LL | a[0] = Default::default();
| ^^^^ 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-use.rs:96:5
|
LL | let [_, _, _x @ ..] = a;
| ------- value moved here
LL | a[0].1 = Default::default();
| ^^^^ 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 14 previous errors

For more information about this error, try `rustc --explain E0382`.
Loading

0 comments on commit d96485d

Please sign in to comment.