Skip to content

Commit

Permalink
Rollup merge of #55700 - pnkfelix:issue-55533-update-ui-tests-wrt-nll…
Browse files Browse the repository at this point in the history
…, r=davidtwco

Update ui tests with respect to NLL

Fix #55533
  • Loading branch information
kennytm committed Nov 6, 2018
2 parents 1ea1a42 + fff9dde commit 6231720
Show file tree
Hide file tree
Showing 43 changed files with 532 additions and 254 deletions.
27 changes: 25 additions & 2 deletions src/test/ui/binop/binop-move-semantics.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ LL | x.clone(); //~ ERROR: use of moved value
|
= note: move occurs because `x` has type `T`, which does not implement the `Copy` trait

error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/binop-move-semantics.rs:31:5
|
LL | let m = &x;
| -- borrow of `x` occurs here
...
LL | x //~ ERROR: cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
...
LL | use_mut(n); use_imm(m);
| - borrow later used here

error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/binop-move-semantics.rs:33:5
|
LL | let n = &mut y;
| ------ borrow of `y` occurs here
...
LL | y; //~ ERROR: cannot move out of `y` because it is borrowed
| ^ move out of `y` occurs here
LL | use_mut(n); use_imm(m);
| - borrow later used here

error[E0507]: cannot move out of borrowed content
--> $DIR/binop-move-semantics.rs:40:5
|
Expand Down Expand Up @@ -62,7 +85,7 @@ LL | | &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also b
| | immutable borrow later used here
| mutable borrow occurs here

error: aborting due to 6 previous errors
error: aborting due to 8 previous errors

Some errors occurred: E0382, E0502, E0507.
Some errors occurred: E0382, E0502, E0505, E0507.
For more information about an error, try `rustc --explain E0382`.
7 changes: 5 additions & 2 deletions src/test/ui/binop/binop-move-semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
x //~ ERROR: cannot move out of `x` because it is borrowed
+
y; //~ ERROR: cannot move out of `y` because it is borrowed
use_mut(n); use_imm(m);
}

fn illegal_dereference<T: Add<Output=()>>(mut x: T, y: T) {
let m = &mut x;
let n = &y;

*m //~ ERROR: cannot move out of borrowed content
+
*n; //~ ERROR: cannot move out of borrowed content
use_imm(n); use_mut(m);
}

struct Foo;

impl<'a, 'b> Add<&'b Foo> for &'a mut Foo {
Expand Down Expand Up @@ -73,3 +73,6 @@ fn immut_plus_mut() {
}

fn main() {}

fn use_mut<T>(_: &mut T) { }
fn use_imm<T>(_: &T) { }
33 changes: 25 additions & 8 deletions src/test/ui/borrowck/borrowck-closures-mut-of-imm.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-closures-mut-of-imm.rs:23:21
--> $DIR/borrowck-closures-mut-of-imm.rs:23:25
|
LL | let c1 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
LL | let mut c1 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable

error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-closures-mut-of-imm.rs:25:21
--> $DIR/borrowck-closures-mut-of-imm.rs:25:25
|
LL | let c2 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable
LL | let mut c2 = || set(&mut *x);
| ^^^^^^^ cannot borrow as mutable

error: aborting due to 2 previous errors
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
|
LL | let mut c1 = || set(&mut *x);
| -- - first borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | //~^ ERROR cannot borrow
LL | let mut c2 = || set(&mut *x);
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
...
LL | c2(); c1();
| -- first borrow later used here

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors occurred: E0524, E0596.
For more information about an error, try `rustc --explain E0524`.
5 changes: 3 additions & 2 deletions src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ fn set(x: &mut isize) {
}

fn a(x: &isize) {
let c1 = || set(&mut *x);
let mut c1 = || set(&mut *x);
//~^ ERROR cannot borrow
let c2 = || set(&mut *x);
let mut c2 = || set(&mut *x);
//~^ ERROR cannot borrow
//~| ERROR two closures require unique access to `x` at the same time
c2(); c1();
}

fn main() {
Expand Down
30 changes: 15 additions & 15 deletions src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-imm.rs:25:14
--> $DIR/borrowck-closures-mut-of-imm.rs:25:18
|
LL | let c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | let mut c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | //~^ ERROR cannot borrow
LL | let c2 = || set(&mut *x);
| ^^ - borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
LL | let mut c2 = || set(&mut *x);
| ^^ - borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
...
LL | }
| - borrow from first closure ends here

error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
--> $DIR/borrowck-closures-mut-of-imm.rs:23:26
--> $DIR/borrowck-closures-mut-of-imm.rs:23:30
|
LL | let c1 = || set(&mut *x);
| ^^ cannot borrow as mutable
LL | let mut c1 = || set(&mut *x);
| ^^ cannot borrow as mutable

error[E0596]: cannot borrow immutable borrowed content `***x` as mutable
--> $DIR/borrowck-closures-mut-of-imm.rs:25:26
--> $DIR/borrowck-closures-mut-of-imm.rs:25:30
|
LL | let c2 = || set(&mut *x);
| ^^ cannot borrow as mutable
LL | let mut c2 = || set(&mut *x);
| ^^ cannot borrow as mutable

error: aborting due to 3 previous errors

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/borrowck/borrowck-closures-mut-of-mut.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
|
LL | let mut c1 = || set(&mut *x);
| -- - first borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | let mut c2 = || set(&mut *x);
| ^^ - second borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
LL | //~^ ERROR two closures require unique access to `x` at the same time
LL | c2(); c1();
| -- first borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0524`.
20 changes: 20 additions & 0 deletions src/test/ui/borrowck/borrowck-closures-mut-of-mut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Tests that two closures cannot simultaneously both have mutable
// access to the variable. Related to issue #6801.

fn get(x: &isize) -> isize {
*x
}

fn set(x: &mut isize) {
*x = 4;
}

fn a(x: &mut isize) {
let mut c1 = || set(&mut *x);
let mut c2 = || set(&mut *x);
//~^ ERROR two closures require unique access to `x` at the same time
c2(); c1();
}

fn main() {
}
18 changes: 18 additions & 0 deletions src/test/ui/borrowck/borrowck-closures-mut-of-mut.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/borrowck-closures-mut-of-mut.rs:14:18
|
LL | let mut c1 = || set(&mut *x);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first closure is constructed here
LL | let mut c2 = || set(&mut *x);
| ^^ - borrow occurs due to use of `x` in closure
| |
| second closure is constructed here
...
LL | }
| - borrow from first closure ends here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0524`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu
LL | let mut x = &mut v;
| - mutable borrow occurs here
...
LL | borrow(&*v); //~ ERROR cannot borrow
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
| ^^ immutable borrow occurs here
LL | }
LL | }
Expand All @@ -16,7 +16,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu
LL | let mut x = &mut v;
| - mutable borrow occurs here
LL | for _ in 0..3 {
LL | borrow(&*v); //~ ERROR cannot borrow
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
| ^^ immutable borrow occurs here
...
LL | }
Expand All @@ -25,7 +25,7 @@ LL | }
error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable
--> $DIR/borrowck-lend-flow-loop.rs:57:25
|
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
| ^^ mutable borrow occurs here
LL | _x = &v;
| - immutable borrow occurs here
Expand All @@ -36,7 +36,7 @@ LL | }
error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable
--> $DIR/borrowck-lend-flow-loop.rs:69:25
|
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
| ^^ mutable borrow occurs here
LL | _x = &v;
| - immutable borrow occurs here
Expand All @@ -50,7 +50,7 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu
LL | _x = &v;
| - immutable borrow occurs here
...
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
| ^^ mutable borrow occurs here
LL | }
| - immutable borrow ends here
Expand All @@ -61,27 +61,27 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu
LL | _x = &v;
| - immutable borrow occurs here
...
LL | borrow_mut(&mut *v); //~ ERROR cannot borrow
LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow
| ^^ mutable borrow occurs here
LL | }
| - immutable borrow ends here

error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mutable
--> $DIR/borrowck-lend-flow-loop.rs:109:17
|
LL | borrow(&*v); //~ ERROR cannot borrow
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
| ^^ immutable borrow occurs here
LL | if cond2 {
LL | x = &mut v; //~ ERROR cannot borrow
...
LL | x = &mut v; //[ast]~ ERROR cannot borrow
| - mutable borrow occurs here
...
LL | }
| - mutable borrow ends here

error[E0499]: cannot borrow `v` as mutable more than once at a time
--> $DIR/borrowck-lend-flow-loop.rs:111:22
--> $DIR/borrowck-lend-flow-loop.rs:112:22
|
LL | x = &mut v; //~ ERROR cannot borrow
LL | x = &mut v; //[ast]~ ERROR cannot borrow
| ^ mutable borrow starts here in previous iteration of loop
...
LL | }
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut
LL | let mut x = &mut v;
| ------ mutable borrow occurs here
LL | for _ in 0..3 {
LL | borrow(&*v); //~ ERROR cannot borrow
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
| ^^^ immutable borrow occurs here
LL | }
...
LL | *x = box 5;
| -- mutable borrow used here, in later iteration of loop

Expand All @@ -15,10 +15,10 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut
|
LL | **x += 1;
| -------- mutable borrow used here, in later iteration of loop
LL | borrow(&*v); //~ ERROR cannot borrow
LL | borrow(&*v); //[ast]~ ERROR cannot borrow
| ^^^ immutable borrow occurs here
LL | if cond2 {
LL | x = &mut v; //~ ERROR cannot borrow
...
LL | x = &mut v; //[ast]~ ERROR cannot borrow
| ------ mutable borrow occurs here

error: aborting due to 2 previous errors
Expand Down
Loading

0 comments on commit 6231720

Please sign in to comment.