Make ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs robust w.r.t. NLL.

This commit is contained in:
Felix S. Klock II 2018-11-05 13:07:51 +01:00
parent 5f524ed5c4
commit cd52b3c2dc
3 changed files with 29 additions and 4 deletions

View file

@ -14,6 +14,16 @@ LL | fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize {
LL | &mut x.y //~ ERROR cannot borrow
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error[E0499]: cannot borrow `*x` as mutable more than once at a time
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:88:19
|
LL | let _x = &mut x.x;
| - first mutable borrow occurs here
LL | let _y = &mut x.y; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | use_mut(_x);
| -- first borrow later used here
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:98:5
|
@ -30,6 +40,16 @@ LL | fn assign_field2<'a>(x: &'a Own<Point>) {
LL | x.y = 3; //~ ERROR cannot borrow
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error[E0499]: cannot borrow `*x` as mutable more than once at a time
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:111:5
|
LL | let _p: &mut Point = &mut **x;
| -- first mutable borrow occurs here
LL | x.y = 3; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | use_mut(_p);
| -- first borrow later used here
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:119:5
|
@ -62,6 +82,7 @@ LL | fn assign_method2<'a>(x: &'a Own<Point>) {
LL | *x.y_mut() = 3; //~ ERROR cannot borrow
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to 8 previous errors
error: aborting due to 10 previous errors
For more information about this error, try `rustc --explain E0596`.
Some errors occurred: E0499, E0596.
For more information about an error, try `rustc --explain E0499`.

View file

@ -86,8 +86,8 @@ fn deref_extend_mut_field3(x: &mut Own<Point>) {
let _x = &mut x.x;
let _y = &mut x.y; //~ ERROR cannot borrow
use_mut(_x);
}
fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
let p = &mut **x;
let _x = &mut p.x;
@ -109,8 +109,8 @@ fn assign_field3<'a>(x: &'a mut Own<Point>) {
fn assign_field4<'a>(x: &'a mut Own<Point>) {
let _p: &mut Point = &mut **x;
x.y = 3; //~ ERROR cannot borrow
use_mut(_p);
}
fn deref_imm_method(x: Own<Point>) {
let __isize = x.get();
}
@ -148,3 +148,5 @@ fn assign_method3<'a>(x: &'a mut Own<Point>) {
}
pub fn main() {}
fn use_mut<T>(_: &mut T) {}

View file

@ -21,6 +21,7 @@ LL | let _x = &mut x.x;
| - first mutable borrow occurs here
LL | let _y = &mut x.y; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | use_mut(_x);
LL | }
| - first borrow ends here
@ -47,6 +48,7 @@ LL | let _p: &mut Point = &mut **x;
| -- first mutable borrow occurs here
LL | x.y = 3; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | use_mut(_p);
LL | }
| - first borrow ends here