Make ui/borrowck/borrowck-unboxed-closures.rs robust w.r.t. NLL.

This commit is contained in:
Felix S. Klock II 2018-11-05 14:32:00 +01:00
parent 6c7d82e1ca
commit 9843a38632
3 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,13 @@
error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-unboxed-closures.rs:13:5
|
LL | let g = &mut f;
| ------ mutable borrow occurs here
LL | f(1, 2); //~ ERROR cannot borrow `f` as immutable
| ^ immutable borrow occurs here
LL | use_mut(g);
| - mutable borrow later used here
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> $DIR/borrowck-unboxed-closures.rs:17:5
|
@ -16,7 +26,7 @@ LL | f(1, 2); //~ ERROR use of moved value
|
= note: move occurs because `f` has type `F`, which does not implement the `Copy` trait
error: aborting due to 2 previous errors
error: aborting due to 3 previous errors
Some errors occurred: E0382, E0596.
Some errors occurred: E0382, E0502, E0596.
For more information about an error, try `rustc --explain E0382`.

View File

@ -11,8 +11,8 @@
fn a<F:Fn(isize, isize) -> isize>(mut f: F) {
let g = &mut f;
f(1, 2); //~ ERROR cannot borrow `f` as immutable
use_mut(g);
}
fn b<F:FnMut(isize, isize) -> isize>(f: F) {
f(1, 2); //~ ERROR cannot borrow immutable argument
}
@ -23,3 +23,5 @@ fn c<F:FnOnce(isize, isize) -> isize>(f: F) {
}
fn main() {}
fn use_mut<T>(_: &mut T) { }

View File

@ -5,6 +5,7 @@ LL | let g = &mut f;
| - mutable borrow occurs here
LL | f(1, 2); //~ ERROR cannot borrow `f` as immutable
| ^ immutable borrow occurs here
LL | use_mut(g);
LL | }
| - mutable borrow ends here