Skip to content

Commit cd52b3c

Browse files
committed
Make ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs robust w.r.t. NLL.
1 parent 5f524ed commit cd52b3c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ LL | fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize {
1414
LL | &mut x.y //~ ERROR cannot borrow
1515
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
1616

17+
error[E0499]: cannot borrow `*x` as mutable more than once at a time
18+
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:88:19
19+
|
20+
LL | let _x = &mut x.x;
21+
| - first mutable borrow occurs here
22+
LL | let _y = &mut x.y; //~ ERROR cannot borrow
23+
| ^ second mutable borrow occurs here
24+
LL | use_mut(_x);
25+
| -- first borrow later used here
26+
1727
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
1828
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:98:5
1929
|
@@ -30,6 +40,16 @@ LL | fn assign_field2<'a>(x: &'a Own<Point>) {
3040
LL | x.y = 3; //~ ERROR cannot borrow
3141
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
3242

43+
error[E0499]: cannot borrow `*x` as mutable more than once at a time
44+
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:111:5
45+
|
46+
LL | let _p: &mut Point = &mut **x;
47+
| -- first mutable borrow occurs here
48+
LL | x.y = 3; //~ ERROR cannot borrow
49+
| ^ second mutable borrow occurs here
50+
LL | use_mut(_p);
51+
| -- first borrow later used here
52+
3353
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
3454
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:119:5
3555
|
@@ -62,6 +82,7 @@ LL | fn assign_method2<'a>(x: &'a Own<Point>) {
6282
LL | *x.y_mut() = 3; //~ ERROR cannot borrow
6383
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6484

65-
error: aborting due to 8 previous errors
85+
error: aborting due to 10 previous errors
6686

67-
For more information about this error, try `rustc --explain E0596`.
87+
Some errors occurred: E0499, E0596.
88+
For more information about an error, try `rustc --explain E0499`.

src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ fn deref_extend_mut_field3(x: &mut Own<Point>) {
8686

8787
let _x = &mut x.x;
8888
let _y = &mut x.y; //~ ERROR cannot borrow
89+
use_mut(_x);
8990
}
90-
9191
fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
9292
let p = &mut **x;
9393
let _x = &mut p.x;
@@ -109,8 +109,8 @@ fn assign_field3<'a>(x: &'a mut Own<Point>) {
109109
fn assign_field4<'a>(x: &'a mut Own<Point>) {
110110
let _p: &mut Point = &mut **x;
111111
x.y = 3; //~ ERROR cannot borrow
112+
use_mut(_p);
112113
}
113-
114114
fn deref_imm_method(x: Own<Point>) {
115115
let __isize = x.get();
116116
}
@@ -148,3 +148,5 @@ fn assign_method3<'a>(x: &'a mut Own<Point>) {
148148
}
149149

150150
pub fn main() {}
151+
152+
fn use_mut<T>(_: &mut T) {}

src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ LL | let _x = &mut x.x;
2121
| - first mutable borrow occurs here
2222
LL | let _y = &mut x.y; //~ ERROR cannot borrow
2323
| ^ second mutable borrow occurs here
24+
LL | use_mut(_x);
2425
LL | }
2526
| - first borrow ends here
2627

@@ -47,6 +48,7 @@ LL | let _p: &mut Point = &mut **x;
4748
| -- first mutable borrow occurs here
4849
LL | x.y = 3; //~ ERROR cannot borrow
4950
| ^ second mutable borrow occurs here
51+
LL | use_mut(_p);
5052
LL | }
5153
| - first borrow ends here
5254

0 commit comments

Comments
 (0)