Updated the most glaring instances of weak tests w.r.t. NLL that came from #53196.

See also the bulletpoint list on #53351.
This commit is contained in:
Felix S. Klock II 2018-08-15 01:16:05 +02:00
parent a5733050de
commit c7041a60a5
45 changed files with 626 additions and 130 deletions

View File

@ -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`.

View File

@ -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);
@ -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 { }

View File

@ -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
@ -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
@ -29,7 +29,7 @@ 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
@ -37,7 +37,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:39:18
--> $DIR/borrow-tuple-fields.rs:43:18
|
LL | let a = &x.0;
| --- immutable borrow occurs here
@ -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

View File

@ -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`.

View File

@ -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 { }

View File

@ -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();
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

View File

@ -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`.

View File

@ -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,
@ -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 { }

View File

@ -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

View File

@ -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`.

View File

@ -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 { }

View File

@ -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`.

View File

@ -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 { }

View File

@ -1,16 +1,16 @@
error[E0504]: cannot move `v` into closure because it is borrowed
--> $DIR/borrowck-loan-blocks-move-cc.rs:25:27
|
LL | let _w = &v;
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;
LL | let w = &v;
| - borrow of `v` occurs here
LL | thread::spawn(move|| {
LL | println!("v={}", *v);

View File

@ -0,0 +1,13 @@
error[E0505]: cannot move out of `v` because it is borrowed
--> $DIR/borrowck-loan-blocks-move.rs:21:10
|
LL | let w = &v;
| -- borrow of `v` occurs here
LL | take(v); //~ ERROR cannot move out of `v` because it is borrowed
| ^ move out of `v` occurs here
LL | w.use_ref();
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.

View File

@ -8,18 +8,22 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
#![feature(box_syntax)]
fn take(_v: Box<isize>) {
}
fn box_imm() {
let v = box 3;
let _w = &v;
let w = &v;
take(v); //~ ERROR cannot move out of `v` because it is borrowed
w.use_ref();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -1,7 +1,7 @@
error[E0505]: cannot move out of `v` because it is borrowed
--> $DIR/borrowck-loan-blocks-move.rs:21:10
|
LL | let _w = &v;
LL | let w = &v;
| - borrow of `v` occurs here
LL | take(v); //~ ERROR cannot move out of `v` because it is borrowed
| ^ move out of `v` occurs here

View File

@ -0,0 +1,14 @@
error[E0505]: cannot move out of `*a` because it is borrowed
--> $DIR/borrowck-move-from-subpath-of-borrowed-path.rs:22:13
|
LL | let b = &a;
| -- borrow of `a` occurs here
LL |
LL | let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
| ^^ move out of `*a` occurs here
LL | b.use_ref();
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// verify that an error is raised when trying to move out of a
// borrowed path.
#![feature(box_syntax)]
fn main() {
@ -20,4 +20,8 @@ fn main() {
let b = &a;
let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
b.use_ref();
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -0,0 +1,14 @@
error[E0505]: cannot move out of `t0` because it is borrowed
--> $DIR/borrowck-move-mut-base-ptr.rs:20:14
|
LL | let p: &isize = &*t0; // Freezes `*t0`
| ---- borrow of `*t0` occurs here
LL | let t1 = t0; //~ ERROR cannot move out of `t0`
| ^^ move out of `t0` occurs here
LL | *t1 = 22;
LL | p.use_ref();
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.

View File

@ -8,18 +8,22 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test that attempt to move `&mut` pointer while pointee is borrowed
// yields an error.
//
// Example from src/librustc_borrowck/borrowck/README.md
fn foo(t0: &mut isize) {
let p: &isize = &*t0; // Freezes `*t0`
let t1 = t0; //~ ERROR cannot move out of `t0`
*t1 = 22;
p.use_ref();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -0,0 +1,26 @@
error[E0502]: cannot borrow `t0` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-mut-borrow-of-mut-base-ptr.rs:21:18
|
LL | let p: &isize = &*t0; // Freezes `*t0`
| ---- immutable borrow occurs here
LL | let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
| ^^^^^^^ mutable borrow occurs here
LL | **t2 += 1; // Mutates `*t0`
LL | p.use_ref();
| - borrow later used here
error[E0499]: cannot borrow `t0` as mutable more than once at a time
--> $DIR/borrowck-mut-borrow-of-mut-base-ptr.rs:29:18
|
LL | let p: &mut isize = &mut *t0; // Claims `*t0`
| -------- first mutable borrow occurs here
LL | let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
| ^^^^^^^ second mutable borrow occurs here
LL | **t2 += 1; // Mutates `*t0` but not through `*p`
LL | p.use_mut();
| - borrow later used here
error: aborting due to 2 previous errors
Some errors occurred: E0499, E0502.
For more information about an error, try `rustc --explain E0499`.

View File

@ -8,18 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test that attempt to mutably borrow `&mut` pointer while pointee is
// borrowed yields an error.
//
// Example from src/librustc_borrowck/borrowck/README.md
fn foo<'a>(mut t0: &'a mut isize,
mut t1: &'a mut isize) {
let p: &isize = &*t0; // Freezes `*t0`
let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
**t2 += 1; // Mutates `*t0`
p.use_ref();
}
fn bar<'a>(mut t0: &'a mut isize,
@ -27,7 +28,11 @@ fn bar<'a>(mut t0: &'a mut isize,
let p: &mut isize = &mut *t0; // Claims `*t0`
let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
**t2 += 1; // Mutates `*t0` but not through `*p`
p.use_mut();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -5,18 +5,18 @@ LL | let p: &isize = &*t0; // Freezes `*t0`
| --- immutable borrow occurs here
LL | let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
| ^^ mutable borrow occurs here
LL | **t2 += 1; // Mutates `*t0`
...
LL | }
| - immutable borrow ends here
error[E0499]: cannot borrow `t0` as mutable more than once at a time
--> $DIR/borrowck-mut-borrow-of-mut-base-ptr.rs:28:23
--> $DIR/borrowck-mut-borrow-of-mut-base-ptr.rs:29:23
|
LL | let p: &mut isize = &mut *t0; // Claims `*t0`
| --- first mutable borrow occurs here
LL | let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
| ^^ second mutable borrow occurs here
LL | **t2 += 1; // Mutates `*t0` but not through `*p`
...
LL | }
| - first borrow ends here

View File

@ -0,0 +1,23 @@
error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-object-lifetime.rs:30:13
|
LL | let y = x.borrowed();
| - immutable borrow occurs here
LL | let z = x.mut_borrowed(); //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL | y.use_ref();
| - borrow later used here
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-object-lifetime.rs:36:13
|
LL | let y = x.borrowed();
| - immutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^^^^^^ mutable borrow occurs here
LL | y.use_ref();
| - borrow later used here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0502`.

View File

@ -8,34 +8,43 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test that borrows that occur due to calls to object methods
// properly "claim" the object path.
trait Foo {
fn borrowed(&self) -> &();
fn mut_borrowed(&mut self) -> &();
}
fn borrowed_receiver(x: &Foo) {
let _y = x.borrowed();
let _z = x.borrowed();
let y = x.borrowed();
let z = x.borrowed();
z.use_ref();
y.use_ref();
}
fn mut_borrowed_receiver(x: &mut Foo) {
let _y = x.borrowed();
let _z = x.mut_borrowed(); //~ ERROR cannot borrow
let y = x.borrowed();
let z = x.mut_borrowed(); //~ ERROR cannot borrow
y.use_ref();
}
fn mut_owned_receiver(mut x: Box<Foo>) {
let _y = x.borrowed();
let _z = &mut x; //~ ERROR cannot borrow
let y = x.borrowed();
let z = &mut x; //~ ERROR cannot borrow
y.use_ref();
}
fn imm_owned_receiver(mut x: Box<Foo>) {
let _y = x.borrowed();
let _z = &x;
let y = x.borrowed();
let z = &x;
z.use_ref();
y.use_ref();
}
fn main() {}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -1,20 +1,22 @@
error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-object-lifetime.rs:28:14
--> $DIR/borrowck-object-lifetime.rs:30:13
|
LL | let _y = x.borrowed();
LL | let y = x.borrowed();
| - immutable borrow occurs here
LL | let _z = x.mut_borrowed(); //~ ERROR cannot borrow
LL | let z = x.mut_borrowed(); //~ ERROR cannot borrow
| ^ mutable borrow occurs here
LL | y.use_ref();
LL | }
| - immutable borrow ends here
error[E0502]: cannot borrow `x` as mutable because `*x` is also borrowed as immutable
--> $DIR/borrowck-object-lifetime.rs:33:19
--> $DIR/borrowck-object-lifetime.rs:36:18
|
LL | let _y = x.borrowed();
LL | let y = x.borrowed();
| - immutable borrow occurs here
LL | let _z = &mut x; //~ ERROR cannot borrow
LL | let z = &mut x; //~ ERROR cannot borrow
| ^ mutable borrow occurs here
LL | y.use_ref();
LL | }
| - immutable borrow ends here

View File

@ -0,0 +1,84 @@
error[E0502]: cannot borrow `*f` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-overloaded-index-autoderef.rs:47:14
|
LL | let p = &mut f[&s];
| - mutable borrow occurs here
LL | let q = &f[&s]; //~ ERROR cannot borrow
| ^ immutable borrow occurs here
LL | p.use_mut();
| - borrow later used here
error[E0499]: cannot borrow `*f` as mutable more than once at a time
--> $DIR/borrowck-overloaded-index-autoderef.rs:53:18
|
LL | let p = &mut f[&s];
| - first mutable borrow occurs here
LL | let q = &mut f[&s]; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | p.use_mut();
| - borrow later used here
error[E0499]: cannot borrow `f.foo` as mutable more than once at a time
--> $DIR/borrowck-overloaded-index-autoderef.rs:63:18
|
LL | let p = &mut f.foo[&s];
| ----- first mutable borrow occurs here
LL | let q = &mut f.foo[&s]; //~ ERROR cannot borrow
| ^^^^^ second mutable borrow occurs here
LL | p.use_mut();
| - borrow later used here
error[E0502]: cannot borrow `f.foo` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-overloaded-index-autoderef.rs:75:18
|
LL | let p = &f.foo[&s];
| ----- immutable borrow occurs here
LL | let q = &mut f.foo[&s]; //~ ERROR cannot borrow
| ^^^^^ mutable borrow occurs here
LL | p.use_ref();
| - borrow later used here
error[E0506]: cannot assign to `f.foo` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:81:5
|
LL | let p = &f.foo[&s];
| ----- borrow of `f.foo` occurs here
LL | f.foo = g; //~ ERROR cannot assign
| ^^^^^^^^^ assignment to borrowed `f.foo` occurs here
LL | p.use_ref();
| - borrow later used here
error[E0506]: cannot assign to `*f` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:87:5
|
LL | let p = &f.foo[&s];
| ----- borrow of `*f` occurs here
LL | *f = g; //~ ERROR cannot assign
| ^^^^^^ assignment to borrowed `*f` occurs here
LL | p.use_ref();
| - borrow later used here
error[E0506]: cannot assign to `f.foo` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:93:5
|
LL | let p = &mut f.foo[&s];
| ----- borrow of `f.foo` occurs here
LL | f.foo = g; //~ ERROR cannot assign
| ^^^^^^^^^ assignment to borrowed `f.foo` occurs here
LL | p.use_mut();
| - borrow later used here
error[E0506]: cannot assign to `*f` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:99:5
|
LL | let p = &mut f.foo[&s];
| ----- borrow of `*f` occurs here
LL | *f = g; //~ ERROR cannot assign
| ^^^^^^ assignment to borrowed `*f` occurs here
LL | p.use_mut();
| - borrow later used here
error: aborting due to 8 previous errors
Some errors occurred: E0499, E0502, E0506.
For more information about an error, try `rustc --explain E0499`.

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test that we still see borrowck errors of various kinds when using
// indexing and autoderef in combination.
use std::ops::{Index, IndexMut};
struct Foo {
x: isize,
y: isize,
@ -43,13 +43,15 @@ impl<'a> IndexMut<&'a String> for Foo {
}
fn test1(mut f: Box<Foo>, s: String) {
let _p = &mut f[&s];
let _q = &f[&s]; //~ ERROR cannot borrow
let p = &mut f[&s];
let q = &f[&s]; //~ ERROR cannot borrow
p.use_mut();
}
fn test2(mut f: Box<Foo>, s: String) {
let _p = &mut f[&s];
let _q = &mut f[&s]; //~ ERROR cannot borrow
let p = &mut f[&s];
let q = &mut f[&s]; //~ ERROR cannot borrow
p.use_mut();
}
struct Bar {
@ -57,39 +59,49 @@ struct Bar {
}
fn test3(mut f: Box<Bar>, s: String) {
let _p = &mut f.foo[&s];
let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
let p = &mut f.foo[&s];
let q = &mut f.foo[&s]; //~ ERROR cannot borrow
p.use_mut();
}
fn test4(mut f: Box<Bar>, s: String) {
let _p = &f.foo[&s];
let _q = &f.foo[&s];
let p = &f.foo[&s];
let q = &f.foo[&s];
p.use_ref();
}
fn test5(mut f: Box<Bar>, s: String) {
let _p = &f.foo[&s];
let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
let p = &f.foo[&s];
let q = &mut f.foo[&s]; //~ ERROR cannot borrow
p.use_ref();
}
fn test6(mut f: Box<Bar>, g: Foo, s: String) {
let _p = &f.foo[&s];
let p = &f.foo[&s];
f.foo = g; //~ ERROR cannot assign
p.use_ref();
}
fn test7(mut f: Box<Bar>, g: Bar, s: String) {
let _p = &f.foo[&s];
let p = &f.foo[&s];
*f = g; //~ ERROR cannot assign
p.use_ref();
}
fn test8(mut f: Box<Bar>, g: Foo, s: String) {
let _p = &mut f.foo[&s];
let p = &mut f.foo[&s];
f.foo = g; //~ ERROR cannot assign
p.use_mut();
}
fn test9(mut f: Box<Bar>, g: Bar, s: String) {
let _p = &mut f.foo[&s];
let p = &mut f.foo[&s];
*f = g; //~ ERROR cannot assign
p.use_mut();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -1,71 +1,75 @@
error[E0502]: cannot borrow `*f` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-overloaded-index-autoderef.rs:47:15
--> $DIR/borrowck-overloaded-index-autoderef.rs:47:14
|
LL | let _p = &mut f[&s];
LL | let p = &mut f[&s];
| - mutable borrow occurs here
LL | let _q = &f[&s]; //~ ERROR cannot borrow
LL | let q = &f[&s]; //~ ERROR cannot borrow
| ^ immutable borrow occurs here
LL | p.use_mut();
LL | }
| - mutable borrow ends here
error[E0499]: cannot borrow `*f` as mutable more than once at a time
--> $DIR/borrowck-overloaded-index-autoderef.rs:52:19
--> $DIR/borrowck-overloaded-index-autoderef.rs:53:18
|
LL | let _p = &mut f[&s];
LL | let p = &mut f[&s];
| - first mutable borrow occurs here
LL | let _q = &mut f[&s]; //~ ERROR cannot borrow
LL | let q = &mut f[&s]; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | p.use_mut();
LL | }
| - first borrow ends here
error[E0499]: cannot borrow `f.foo` as mutable more than once at a time
--> $DIR/borrowck-overloaded-index-autoderef.rs:61:19
--> $DIR/borrowck-overloaded-index-autoderef.rs:63:18
|
LL | let _p = &mut f.foo[&s];
LL | let p = &mut f.foo[&s];
| ----- first mutable borrow occurs here
LL | let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
LL | let q = &mut f.foo[&s]; //~ ERROR cannot borrow
| ^^^^^ second mutable borrow occurs here
LL | p.use_mut();
LL | }
| - first borrow ends here
error[E0502]: cannot borrow `f.foo` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-overloaded-index-autoderef.rs:71:19
--> $DIR/borrowck-overloaded-index-autoderef.rs:75:18
|
LL | let _p = &f.foo[&s];
LL | let p = &f.foo[&s];
| ----- immutable borrow occurs here
LL | let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
LL | let q = &mut f.foo[&s]; //~ ERROR cannot borrow
| ^^^^^ mutable borrow occurs here
LL | p.use_ref();
LL | }
| - immutable borrow ends here
error[E0506]: cannot assign to `f.foo` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:76:5
--> $DIR/borrowck-overloaded-index-autoderef.rs:81:5
|
LL | let _p = &f.foo[&s];
LL | let p = &f.foo[&s];
| ----- borrow of `f.foo` occurs here
LL | f.foo = g; //~ ERROR cannot assign
| ^^^^^^^^^ assignment to borrowed `f.foo` occurs here
error[E0506]: cannot assign to `*f` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:81:5
--> $DIR/borrowck-overloaded-index-autoderef.rs:87:5
|
LL | let _p = &f.foo[&s];
LL | let p = &f.foo[&s];
| ----- borrow of `*f` occurs here
LL | *f = g; //~ ERROR cannot assign
| ^^^^^^ assignment to borrowed `*f` occurs here
error[E0506]: cannot assign to `f.foo` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:86:5
--> $DIR/borrowck-overloaded-index-autoderef.rs:93:5
|
LL | let _p = &mut f.foo[&s];
LL | let p = &mut f.foo[&s];
| ----- borrow of `f.foo` occurs here
LL | f.foo = g; //~ ERROR cannot assign
| ^^^^^^^^^ assignment to borrowed `f.foo` occurs here
error[E0506]: cannot assign to `*f` because it is borrowed
--> $DIR/borrowck-overloaded-index-autoderef.rs:91:5
--> $DIR/borrowck-overloaded-index-autoderef.rs:99:5
|
LL | let _p = &mut f.foo[&s];
LL | let p = &mut f.foo[&s];
| ----- borrow of `*f` occurs here
LL | *f = g; //~ ERROR cannot assign
| ^^^^^^ assignment to borrowed `*f` occurs here

View File

@ -0,0 +1,14 @@
error[E0502]: cannot borrow `t0` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-swap-mut-base-ptr.rs:23:10
|
LL | let p: &isize = &*t0; // Freezes `*t0`
| ---- immutable borrow occurs here
LL | swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
| ^^^^^^^ mutable borrow occurs here
LL | *t1 = 22;
LL | p.use_ref();
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0502`.

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test that attempt to swap `&mut` pointer while pointee is borrowed
// yields an error.
//
@ -17,12 +15,18 @@
use std::mem::swap;
fn foo<'a>(mut t0: &'a mut isize,
mut t1: &'a mut isize) {
let p: &isize = &*t0; // Freezes `*t0`
swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
*t1 = 22;
p.use_ref();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -5,7 +5,7 @@ LL | let p: &isize = &*t0; // Freezes `*t0`
| --- immutable borrow occurs here
LL | swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
| ^^ mutable borrow occurs here
LL | *t1 = 22;
...
LL | }
| - immutable borrow ends here

View File

@ -0,0 +1,13 @@
error[E0503]: cannot use `u.c` because it was mutably borrowed
--> $DIR/borrowck-union-borrow-nested.rs:36:21
|
LL | let ra = &mut u.s.a;
| ---------- borrow of `u.s.a` occurs here
LL | let b = u.c; //~ ERROR cannot use `u.c` because it was mutably borrowed
| ^^^ use of borrowed `u.s.a`
LL | ra.use_mut();
| -- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0503`.

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
#[derive(Clone, Copy)]
struct S {
@ -28,11 +28,16 @@ fn main() {
let mut u = U { s: S { a: 0, b: 1 } };
let ra = &mut u.s.a;
let b = u.s.b; // OK
ra.use_mut();
}
{
let mut u = U { s: S { a: 0, b: 1 } };
let ra = &mut u.s.a;
let b = u.c; //~ ERROR cannot use `u.c` because it was mutably borrowed
ra.use_mut();
}
}
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -1,5 +1,5 @@
error[E0503]: cannot use `u.c` because it was mutably borrowed
--> $DIR/borrowck-union-borrow-nested.rs:35:17
--> $DIR/borrowck-union-borrow-nested.rs:36:17
|
LL | let ra = &mut u.s.a;
| ----- borrow of `u.s.a` occurs here

View File

@ -0,0 +1,23 @@
error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-uniq-via-lend.rs:46:12
|
LL | let w = &mut v;
| ------ mutable borrow occurs here
LL | borrow(&*v); //~ ERROR cannot borrow `*v`
| ^^^ immutable borrow occurs here
LL | w.use_mut();
| - borrow later used here
error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-uniq-via-lend.rs:63:12
|
LL | x = &mut v;
| ------ mutable borrow occurs here
LL | borrow(&*v); //~ ERROR cannot borrow `*v`
| ^^^ immutable borrow occurs here
LL | x.use_mut();
| - borrow later used here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0502`.

View File

@ -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)]
fn borrow(_v: &isize) {}
fn local() {
@ -35,30 +35,37 @@ fn local_recs() {
fn aliased_imm() {
let mut v: Box<_> = box 3;
let _w = &v;
let w = &v;
borrow(&*v);
w.use_ref();
}
fn aliased_mut() {
let mut v: Box<_> = box 3;
let _w = &mut v;
let w = &mut v;
borrow(&*v); //~ ERROR cannot borrow `*v`
w.use_mut();
}
fn aliased_other() {
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let _x = &mut w;
let x = &mut w;
borrow(&*v);
x.use_mut();
}
fn aliased_other_reassign() {
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &mut w;
_x = &mut v;
let mut x = &mut w;
x = &mut v;
borrow(&*v); //~ ERROR cannot borrow `*v`
x.use_mut();
}
fn main() {
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -1,20 +1,22 @@
error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mutable
--> $DIR/borrowck-uniq-via-lend.rs:45:13
--> $DIR/borrowck-uniq-via-lend.rs:46:13
|
LL | let _w = &mut v;
LL | let w = &mut v;
| - mutable borrow occurs here
LL | borrow(&*v); //~ ERROR cannot borrow `*v`
| ^^ immutable borrow occurs here
LL | w.use_mut();
LL | }
| - mutable borrow ends here
error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mutable
--> $DIR/borrowck-uniq-via-lend.rs:60:13
--> $DIR/borrowck-uniq-via-lend.rs:63:13
|
LL | _x = &mut v;
LL | x = &mut v;
| - mutable borrow occurs here
LL | borrow(&*v); //~ ERROR cannot borrow `*v`
| ^^ immutable borrow occurs here
LL | x.use_mut();
LL | }
| - mutable borrow ends here

View File

@ -0,0 +1,24 @@
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
--> $DIR/method-self-arg-2.rs:25:14
|
LL | let y = &mut x;
| ------ mutable borrow occurs here
LL | Foo::bar(&x); //~ERROR cannot borrow `x`
| ^^ immutable borrow occurs here
LL | y.use_mut();
| - borrow later used here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/method-self-arg-2.rs:30:14
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
LL | Foo::baz(&mut x); //~ERROR cannot borrow `x`
| ^^^^^^ second mutable borrow occurs here
LL | y.use_mut();
| - borrow later used here
error: aborting due to 2 previous errors
Some errors occurred: E0499, E0502.
For more information about an error, try `rustc --explain E0499`.

View File

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
// Test method calls with self as an argument cannot subvert borrow checking.
struct Foo;
impl Foo {
@ -23,8 +23,13 @@ fn main() {
let mut x = Foo;
let y = &mut x;
Foo::bar(&x); //~ERROR cannot borrow `x`
y.use_mut();
let mut x = Foo;
let y = &mut x;
Foo::baz(&mut x); //~ERROR cannot borrow `x`
y.use_mut();
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -10,12 +10,13 @@ LL | }
| - mutable borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/method-self-arg-2.rs:29:19
--> $DIR/method-self-arg-2.rs:30:19
|
LL | let y = &mut x;
| - first mutable borrow occurs here
LL | Foo::baz(&mut x); //~ERROR cannot borrow `x`
| ^ second mutable borrow occurs here
LL | y.use_mut();
LL | }
| - first borrow ends here

View File

@ -0,0 +1,13 @@
error[E0499]: cannot borrow `b` as mutable more than once at a time
--> $DIR/mut-cant-alias.rs:19:20
|
LL | let b1 = &mut *b;
| - first mutable borrow occurs here
LL | let b2 = &mut *b; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | b1.use_mut();
| -- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0499`.

View File

@ -8,13 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-compare-mode-nll
use std::cell::RefCell;
fn main() {
let m = RefCell::new(0);
let mut b = m.borrow_mut();
let b1 = &mut *b;
let b2 = &mut *b; //~ ERROR cannot borrow
b1.use_mut();
}
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }

View File

@ -5,6 +5,7 @@ LL | let b1 = &mut *b;
| - first mutable borrow occurs here
LL | let b2 = &mut *b; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | b1.use_mut();
LL | }
| - first borrow ends here