diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-11-05 13:07:51 +0100 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-11-05 15:26:02 +0100 |
| commit | cd52b3c2dccf64829112fe56995e25f2b75591df (patch) | |
| tree | 11eee238f8664ffa1bb24e7865865098d2b12483 | |
| parent | 5f524ed5c4b0d5e0bf6a6ea52284704411712c82 (diff) | |
| download | rust-cd52b3c2dccf64829112fe56995e25f2b75591df.tar.gz rust-cd52b3c2dccf64829112fe56995e25f2b75591df.zip | |
Make `ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs` robust w.r.t. NLL.
3 files changed, 29 insertions, 4 deletions
diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr index 4a693a3b05d..389a1116c16 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr @@ -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`. diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs index 764d05be879..48eb2e239f7 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs @@ -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) {} diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr index d91ff696423..864357fee9f 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr @@ -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 |
