Skip to content

Commit

Permalink
Updated the most glaring instances of weak tests w.r.t. NLL that came…
Browse files Browse the repository at this point in the history
… from rust-lang#53196.

See also the bulletpoint list on rust-lang#53351.
  • Loading branch information
pnkfelix committed Aug 14, 2018
1 parent a573305 commit c7041a6
Show file tree
Hide file tree
Showing 45 changed files with 626 additions and 130 deletions.
65 changes: 65 additions & 0 deletions src/test/ui/borrowck/borrow-tuple-fields.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:22:13
|
LL | let r = &x.0;
| ---- borrow of `x.0` occurs here
LL | let y = x; //~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
LL |
LL | r.use_ref();
| - borrow later used here

error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:28:13
|
LL | let a = &x.0;
| ---- immutable borrow occurs here
LL | let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - borrow later used here

error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:33:13
|
LL | let a = &mut x.0;
| -------- first mutable borrow occurs here
LL | let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_ref();
| - borrow later used here

error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:38:13
|
LL | let r = &x.0;
| ---- borrow of `x.0` occurs here
LL | let y = x; //~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
LL | r.use_ref();
| - borrow later used here

error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:43:13
|
LL | let a = &x.0;
| ---- immutable borrow occurs here
LL | let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - borrow later used here

error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:48:13
|
LL | let a = &mut x.0;
| -------- first mutable borrow occurs here
LL | let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_mut();
| - borrow later used here

error: aborting due to 6 previous errors

Some errors occurred: E0499, E0502, E0505.
For more information about an error, try `rustc --explain E0499`.
15 changes: 12 additions & 3 deletions src/test/ui/borrowck/borrow-tuple-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-compare-mode-nll

#![feature(box_syntax)]



struct Foo(Box<isize>, isize);

struct Bar(isize, isize);
Expand All @@ -21,24 +21,33 @@ fn main() {
let r = &x.0;
let y = x; //~ ERROR cannot move out of `x` because it is borrowed

r.use_ref();

let mut x = (1, 2);
let a = &x.0;
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
a.use_ref();

let mut x = (1, 2);
let a = &mut x.0;
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time

a.use_ref();

let x = Foo(box 1, 2);
let r = &x.0;
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
r.use_ref();

let mut x = Bar(1, 2);
let a = &x.0;
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
a.use_ref();

let mut x = Bar(1, 2);
let a = &mut x.0;
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
a.use_mut();
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
11 changes: 6 additions & 5 deletions src/test/ui/borrowck/borrow-tuple-fields.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | let y = x; //~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here

error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:26:18
--> $DIR/borrow-tuple-fields.rs:28:18
|
LL | let a = &x.0;
| --- immutable borrow occurs here
Expand All @@ -18,7 +18,7 @@ LL | }
| - immutable borrow ends here

error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:30:18
--> $DIR/borrow-tuple-fields.rs:33:18
|
LL | let a = &mut x.0;
| --- first mutable borrow occurs here
Expand All @@ -29,15 +29,15 @@ LL | }
| - first borrow ends here

error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:35:9
--> $DIR/borrow-tuple-fields.rs:38:9
|
LL | let r = &x.0;
| --- borrow of `x.0` occurs here
LL | let y = x; //~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here

error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:39:18
--> $DIR/borrow-tuple-fields.rs:43:18
|
LL | let a = &x.0;
| --- immutable borrow occurs here
Expand All @@ -48,12 +48,13 @@ LL | }
| - immutable borrow ends here

error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:43:18
--> $DIR/borrow-tuple-fields.rs:48:18
|
LL | let a = &mut x.0;
| --- first mutable borrow occurs here
LL | let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
| ^^^ second mutable borrow occurs here
LL | a.use_mut();
LL | }
| - first borrow ends here

Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/borrowck/borrowck-borrow-mut-object-twice.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0499]: cannot borrow `*x` as mutable more than once at a time
--> $DIR/borrowck-borrow-mut-object-twice.rs:23:5
|
LL | let y = x.f1();
| - first mutable borrow occurs here
LL | x.f2(); //~ ERROR cannot borrow `*x` as mutable
| ^ second mutable borrow occurs here
LL | y.use_ref();
| - borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0499`.
10 changes: 7 additions & 3 deletions src/test/ui/borrowck/borrowck-borrow-mut-object-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-compare-mode-nll

// Check that `&mut` objects cannot be borrowed twice, just like
// other `&mut` pointers.



trait Foo {
fn f1(&mut self) -> &();
fn f2(&mut self);
}

fn test(x: &mut Foo) {
let _y = x.f1();
let y = x.f1();
x.f2(); //~ ERROR cannot borrow `*x` as mutable
y.use_ref();
}

fn main() {}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
5 changes: 3 additions & 2 deletions src/test/ui/borrowck/borrowck-borrow-mut-object-twice.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error[E0499]: cannot borrow `*x` as mutable more than once at a time
--> $DIR/borrowck-borrow-mut-object-twice.rs:23:5
|
LL | let _y = x.f1();
| - first mutable borrow occurs here
LL | let y = x.f1();
| - first mutable borrow occurs here
LL | x.f2(); //~ ERROR cannot borrow `*x` as mutable
| ^ second mutable borrow occurs here
LL | y.use_ref();
LL | }
| - first borrow ends here

Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/borrowck/borrowck-closures-unique-imm.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0502]: cannot borrow `this.x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-closures-unique-imm.rs:23:9
|
LL | let p = &this.x;
| ------- immutable borrow occurs here
LL | &mut this.x; //~ ERROR cannot borrow
| ^^^^^^^^^^^ mutable borrow occurs here
LL | p.use_ref();
| - borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0502`.
6 changes: 5 additions & 1 deletion src/test/ui/borrowck/borrowck-closures-unique-imm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-compare-mode-nll


struct Foo {
x: isize,
Expand All @@ -21,6 +21,10 @@ pub fn main() {
let mut r = || {
let p = &this.x;
&mut this.x; //~ ERROR cannot borrow
p.use_ref();
};
r()
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
1 change: 1 addition & 0 deletions src/test/ui/borrowck/borrowck-closures-unique-imm.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let p = &this.x;
| ------ immutable borrow occurs here
LL | &mut this.x; //~ ERROR cannot borrow
| ^^^^^^ mutable borrow occurs here
LL | p.use_ref();
LL | };
| - immutable borrow ends here

Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/borrowck/borrowck-issue-2657-1.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrowck-issue-2657-1.rs:19:18
|
LL | Some(ref _y) => {
| ------ borrow of `x.0` occurs here
LL | let _a = x; //~ ERROR cannot move
| ^ move out of `x` occurs here
LL | _y.use_ref();
| -- borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0505`.
8 changes: 6 additions & 2 deletions src/test/ui/borrowck/borrowck-issue-2657-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-compare-mode-nll

#![feature(box_syntax)]



fn main() {
let x: Option<Box<_>> = Some(box 1);
match x {
Some(ref _y) => {
let _a = x; //~ ERROR cannot move
_y.use_ref();
}
_ => {}
}
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
29 changes: 29 additions & 0 deletions src/test/ui/borrowck/borrowck-loan-blocks-move-cc.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0505]: cannot move out of `v` because it is borrowed
--> $DIR/borrowck-loan-blocks-move-cc.rs:24:19
|
LL | let w = &v;
| -- borrow of `v` occurs here
LL | thread::spawn(move|| {
| ^^^^^^ move out of `v` occurs here
LL | println!("v={}", *v);
| - move occurs due to use in closure
...
LL | w.use_ref();
| - borrow later used here

error[E0505]: cannot move out of `v` because it is borrowed
--> $DIR/borrowck-loan-blocks-move-cc.rs:34:19
|
LL | let w = &v;
| -- borrow of `v` occurs here
LL | thread::spawn(move|| {
| ^^^^^^ move out of `v` occurs here
LL | println!("v={}", *v);
| - move occurs due to use in closure
...
LL | w.use_ref();
| - borrow later used here

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0505`.
13 changes: 9 additions & 4 deletions src/test/ui/borrowck/borrowck-loan-blocks-move-cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,38 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-compare-mode-nll

#![feature(box_syntax)]

use std::thread;



fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
f(v);
}

fn box_imm() {
let v: Box<_> = box 3;
let _w = &v;
let w = &v;
thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
w.use_ref();
}

fn box_imm_explicit() {
let v: Box<_> = box 3;
let _w = &v;
let w = &v;
thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move
});
w.use_ref();
}

fn main() {
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
10 changes: 5 additions & 5 deletions src/test/ui/borrowck/borrowck-loan-blocks-move-cc.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0504]: cannot move `v` into closure because it is borrowed
--> $DIR/borrowck-loan-blocks-move-cc.rs:25:27
|
LL | let _w = &v;
| - borrow of `v` occurs here
LL | let w = &v;
| - borrow of `v` occurs here
LL | thread::spawn(move|| {
LL | println!("v={}", *v);
| ^ move into closure occurs here

error[E0504]: cannot move `v` into closure because it is borrowed
--> $DIR/borrowck-loan-blocks-move-cc.rs:34:27
--> $DIR/borrowck-loan-blocks-move-cc.rs:35:27
|
LL | let _w = &v;
| - borrow of `v` occurs here
LL | let w = &v;
| - borrow of `v` occurs here
LL | thread::spawn(move|| {
LL | println!("v={}", *v);
| ^ move into closure occurs here
Expand Down
Loading

0 comments on commit c7041a6

Please sign in to comment.