diff --git a/src/test/ui/borrowck/borrow-tuple-fields.nll.stderr b/src/test/ui/borrowck/borrow-tuple-fields.nll.stderr new file mode 100644 index 0000000000000..855488e1eef1b --- /dev/null +++ b/src/test/ui/borrowck/borrow-tuple-fields.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrow-tuple-fields.rs b/src/test/ui/borrowck/borrow-tuple-fields.rs index 4337f569fa4c0..de3a5c799cbbf 100644 --- a/src/test/ui/borrowck/borrow-tuple-fields.rs +++ b/src/test/ui/borrowck/borrow-tuple-fields.rs @@ -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); 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 Fake for T { } diff --git a/src/test/ui/borrowck/borrow-tuple-fields.stderr b/src/test/ui/borrowck/borrow-tuple-fields.stderr index d010d1d989c9b..1cbfcdfc06a3a 100644 --- a/src/test/ui/borrowck/borrow-tuple-fields.stderr +++ b/src/test/ui/borrowck/borrow-tuple-fields.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.nll.stderr b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.nll.stderr new file mode 100644 index 0000000000000..9c3d0b170d90e --- /dev/null +++ b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.rs b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.rs index 910851a1030c5..63a64631f44a0 100644 --- a/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.rs +++ b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.stderr b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.stderr index e0ea39a249176..de2fa8db96f64 100644 --- a/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.stderr +++ b/src/test/ui/borrowck/borrowck-borrow-mut-object-twice.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-closures-unique-imm.nll.stderr b/src/test/ui/borrowck/borrowck-closures-unique-imm.nll.stderr new file mode 100644 index 0000000000000..b8f17570a6471 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-closures-unique-imm.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-closures-unique-imm.rs b/src/test/ui/borrowck/borrowck-closures-unique-imm.rs index 9fefbe2bdc690..c4b15a9c0fe4d 100644 --- a/src/test/ui/borrowck/borrowck-closures-unique-imm.rs +++ b/src/test/ui/borrowck/borrowck-closures-unique-imm.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-closures-unique-imm.stderr b/src/test/ui/borrowck/borrowck-closures-unique-imm.stderr index a166b6292e654..5ab9685850ee4 100644 --- a/src/test/ui/borrowck/borrowck-closures-unique-imm.stderr +++ b/src/test/ui/borrowck/borrowck-closures-unique-imm.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-issue-2657-1.nll.stderr b/src/test/ui/borrowck/borrowck-issue-2657-1.nll.stderr new file mode 100644 index 0000000000000..8d2bef315c854 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-issue-2657-1.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-issue-2657-1.rs b/src/test/ui/borrowck/borrowck-issue-2657-1.rs index 500de9865dcce..3eb939c0ddadd 100644 --- a/src/test/ui/borrowck/borrowck-issue-2657-1.rs +++ b/src/test/ui/borrowck/borrowck-issue-2657-1.rs @@ -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> = 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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.nll.stderr b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.nll.stderr new file mode 100644 index 0000000000000..6f0f23b24c646 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.rs b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.rs index e57575d8f03d4..27296085d9a41 100644 --- a/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.rs +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.rs @@ -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(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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.stderr b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.stderr index a1d633e54f021..575672959929c 100644 --- a/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.stderr +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move-cc.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move.nll.stderr b/src/test/ui/borrowck/borrowck-loan-blocks-move.nll.stderr new file mode 100644 index 0000000000000..432137cdae1ba --- /dev/null +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move.rs b/src/test/ui/borrowck/borrowck-loan-blocks-move.rs index dc83dc731b353..b1241ae020efc 100644 --- a/src/test/ui/borrowck/borrowck-loan-blocks-move.rs +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move.rs @@ -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) { } 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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-loan-blocks-move.stderr b/src/test/ui/borrowck/borrowck-loan-blocks-move.stderr index fb5657f6928a4..5edbf6a9b2c21 100644 --- a/src/test/ui/borrowck/borrowck-loan-blocks-move.stderr +++ b/src/test/ui/borrowck/borrowck-loan-blocks-move.stderr @@ -1,8 +1,8 @@ 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 | 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 diff --git a/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.nll.stderr b/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.nll.stderr new file mode 100644 index 0000000000000..bd5d19ffe054c --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs b/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs index 8423b4cc9b0b2..1216fb89667e8 100644 --- a/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs +++ b/src/test/ui/borrowck/borrowck-move-from-subpath-of-borrowed-path.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-move-mut-base-ptr.nll.stderr b/src/test/ui/borrowck/borrowck-move-mut-base-ptr.nll.stderr new file mode 100644 index 0000000000000..9d31d2b4aff9f --- /dev/null +++ b/src/test/ui/borrowck/borrowck-move-mut-base-ptr.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-move-mut-base-ptr.rs b/src/test/ui/borrowck/borrowck-move-mut-base-ptr.rs index d18f962397416..eb7b310a8bf07 100644 --- a/src/test/ui/borrowck/borrowck-move-mut-base-ptr.rs +++ b/src/test/ui/borrowck/borrowck-move-mut-base-ptr.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.nll.stderr b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.nll.stderr new file mode 100644 index 0000000000000..0684e787bae7f --- /dev/null +++ b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs index 5b73ca8e49a44..45768ef51146e 100644 --- a/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs +++ b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.stderr b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.stderr index e7d41dd46028d..d5b8831962978 100644 --- a/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.stderr +++ b/src/test/ui/borrowck/borrowck-mut-borrow-of-mut-base-ptr.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-object-lifetime.nll.stderr b/src/test/ui/borrowck/borrowck-object-lifetime.nll.stderr new file mode 100644 index 0000000000000..e4e2dfe86bd83 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-object-lifetime.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-object-lifetime.rs b/src/test/ui/borrowck/borrowck-object-lifetime.rs index 23148304d6c4e..cb7486aefa28b 100644 --- a/src/test/ui/borrowck/borrowck-object-lifetime.rs +++ b/src/test/ui/borrowck/borrowck-object-lifetime.rs @@ -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) { - 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) { - 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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-object-lifetime.stderr b/src/test/ui/borrowck/borrowck-object-lifetime.stderr index 5680007579548..5e9045d3e3868 100644 --- a/src/test/ui/borrowck/borrowck-object-lifetime.stderr +++ b/src/test/ui/borrowck/borrowck-object-lifetime.stderr @@ -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(); - | - immutable borrow occurs here -LL | let _z = x.mut_borrowed(); //~ ERROR cannot borrow - | ^ mutable borrow occurs here +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(); 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(); - | - immutable borrow occurs here -LL | let _z = &mut x; //~ ERROR cannot borrow - | ^ mutable borrow occurs here +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(); LL | } | - immutable borrow ends here diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.nll.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.nll.stderr new file mode 100644 index 0000000000000..994492d8575c9 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.rs b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.rs index 51d154c0f3abc..5ab3d75f18178 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.rs +++ b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.rs @@ -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, 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, 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, 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, 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, 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, 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, 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, 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, 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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.stderr index d269ce5ec34c3..7a17a5570e4be 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-index-autoderef.stderr @@ -1,72 +1,76 @@ 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]; - | - mutable borrow occurs here -LL | let _q = &f[&s]; //~ ERROR cannot borrow - | ^ immutable borrow occurs here +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(); 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]; - | - first mutable borrow occurs here -LL | let _q = &mut f[&s]; //~ ERROR cannot borrow - | ^ second mutable borrow occurs here +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(); 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]; - | ----- first mutable borrow occurs here -LL | let _q = &mut f.foo[&s]; //~ ERROR cannot borrow - | ^^^^^ second mutable borrow occurs here +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(); 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]; - | ----- immutable borrow occurs here -LL | let _q = &mut f.foo[&s]; //~ ERROR cannot borrow - | ^^^^^ mutable borrow occurs here +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(); 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]; - | ----- borrow of `f.foo` occurs here +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]; - | ----- borrow of `*f` occurs here +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]; - | ----- borrow of `f.foo` occurs here +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]; - | ----- borrow of `*f` occurs here +LL | let p = &mut f.foo[&s]; + | ----- borrow of `*f` occurs here LL | *f = g; //~ ERROR cannot assign | ^^^^^^ assignment to borrowed `*f` occurs here diff --git a/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.nll.stderr b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.nll.stderr new file mode 100644 index 0000000000000..5f605694c5bcc --- /dev/null +++ b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.rs b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.rs index cf9fab9f0a183..b4b78bbb747fb 100644 --- a/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.rs +++ b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.stderr b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.stderr index f9e4a580ccc6c..27824725e53ed 100644 --- a/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.stderr +++ b/src/test/ui/borrowck/borrowck-swap-mut-base-ptr.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-union-borrow-nested.nll.stderr b/src/test/ui/borrowck/borrowck-union-borrow-nested.nll.stderr new file mode 100644 index 0000000000000..eaba196f8ac7a --- /dev/null +++ b/src/test/ui/borrowck/borrowck-union-borrow-nested.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-union-borrow-nested.rs b/src/test/ui/borrowck/borrowck-union-borrow-nested.rs index f1c4e4c1869c5..0839d2430a970 100644 --- a/src/test/ui/borrowck/borrowck-union-borrow-nested.rs +++ b/src/test/ui/borrowck/borrowck-union-borrow-nested.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-union-borrow-nested.stderr b/src/test/ui/borrowck/borrowck-union-borrow-nested.stderr index 4e7392a422814..8f90254469b59 100644 --- a/src/test/ui/borrowck/borrowck-union-borrow-nested.stderr +++ b/src/test/ui/borrowck/borrowck-union-borrow-nested.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-uniq-via-lend.nll.stderr b/src/test/ui/borrowck/borrowck-uniq-via-lend.nll.stderr new file mode 100644 index 0000000000000..a918550fabfc1 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-uniq-via-lend.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-uniq-via-lend.rs b/src/test/ui/borrowck/borrowck-uniq-via-lend.rs index 5a4e27768afc3..6fbadc9be25d2 100644 --- a/src/test/ui/borrowck/borrowck-uniq-via-lend.rs +++ b/src/test/ui/borrowck/borrowck-uniq-via-lend.rs @@ -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 Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-uniq-via-lend.stderr b/src/test/ui/borrowck/borrowck-uniq-via-lend.stderr index b731a6192d132..00b4344018396 100644 --- a/src/test/ui/borrowck/borrowck-uniq-via-lend.stderr +++ b/src/test/ui/borrowck/borrowck-uniq-via-lend.stderr @@ -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; - | - mutable borrow occurs here +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; - | - mutable borrow occurs here +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 diff --git a/src/test/ui/methods/method-self-arg-2.nll.stderr b/src/test/ui/methods/method-self-arg-2.nll.stderr new file mode 100644 index 0000000000000..f876aa281d111 --- /dev/null +++ b/src/test/ui/methods/method-self-arg-2.nll.stderr @@ -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`. diff --git a/src/test/ui/methods/method-self-arg-2.rs b/src/test/ui/methods/method-self-arg-2.rs index 397c6eab536c5..cba4e6da6d99b 100644 --- a/src/test/ui/methods/method-self-arg-2.rs +++ b/src/test/ui/methods/method-self-arg-2.rs @@ -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 Fake for T { } diff --git a/src/test/ui/methods/method-self-arg-2.stderr b/src/test/ui/methods/method-self-arg-2.stderr index 4fe2da4164fa7..0bfa6034135a2 100644 --- a/src/test/ui/methods/method-self-arg-2.stderr +++ b/src/test/ui/methods/method-self-arg-2.stderr @@ -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 diff --git a/src/test/ui/mut/mut-cant-alias.nll.stderr b/src/test/ui/mut/mut-cant-alias.nll.stderr new file mode 100644 index 0000000000000..e2758f810db7d --- /dev/null +++ b/src/test/ui/mut/mut-cant-alias.nll.stderr @@ -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`. diff --git a/src/test/ui/mut/mut-cant-alias.rs b/src/test/ui/mut/mut-cant-alias.rs index 15e1be66e78f8..af7d0e2742a0f 100644 --- a/src/test/ui/mut/mut-cant-alias.rs +++ b/src/test/ui/mut/mut-cant-alias.rs @@ -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 Fake for T { } diff --git a/src/test/ui/mut/mut-cant-alias.stderr b/src/test/ui/mut/mut-cant-alias.stderr index b9497940301c6..b15ffe649dd63 100644 --- a/src/test/ui/mut/mut-cant-alias.stderr +++ b/src/test/ui/mut/mut-cant-alias.stderr @@ -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