Skip to content

Commit be2ec32

Browse files
committed
Account for * when looking for inner-most path in expression
1 parent e4f61af commit be2ec32

8 files changed

+31
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
7575
let mut expr_finder = FindExprBySpan::new(span);
7676
expr_finder.visit_expr(body.value);
7777
if let Some(mut expr) = expr_finder.result {
78-
while let hir::ExprKind::AddrOf(_, _, inner) = &expr.kind {
78+
while let hir::ExprKind::AddrOf(_, _, inner)
79+
| hir::ExprKind::Unary(hir::UnOp::Deref, inner) = &expr.kind
80+
{
7981
expr = inner;
8082
}
8183
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind

tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error[E0505]: cannot move out of `a` because it is borrowed
22
--> $DIR/borrowck-bad-nested-calls-move.rs:25:9
33
|
4+
LL | let mut a: Box<_> = Box::new(1);
5+
| ----- binding `a` declared here
6+
...
47
LL | add(
58
| --- borrow later used by call
69
LL | &*a,
@@ -11,6 +14,8 @@ LL | a);
1114
error[E0505]: cannot move out of `a` because it is borrowed
1215
--> $DIR/borrowck-bad-nested-calls-move.rs:32:9
1316
|
17+
LL | let mut a: Box<_> = Box::new(1);
18+
| ----- binding `a` declared here
1419
LL | add(
1520
| --- borrow later used by call
1621
LL | &*a,

tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0505]: cannot move out of `t0` because it is borrowed
22
--> $DIR/borrowck-move-mut-base-ptr.rs:10:14
33
|
4+
LL | fn foo(t0: &mut isize) {
5+
| -- binding `t0` declared here
46
LL | let p: &isize = &*t0; // Freezes `*t0`
57
| ---- borrow of `*t0` occurs here
68
LL | let t1 = t0;

tests/ui/borrowck/borrowck-unary-move.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0505]: cannot move out of `x` because it is borrowed
22
--> $DIR/borrowck-unary-move.rs:3:10
33
|
4+
LL | fn foo(x: Box<isize>) -> isize {
5+
| - binding `x` declared here
46
LL | let y = &*x;
57
| --- borrow of `*x` occurs here
68
LL | free(x);

tests/ui/nll/polonius/polonius-smoke-test.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ error[E0505]: cannot move out of `x` because it is borrowed
1818
--> $DIR/polonius-smoke-test.rs:18:13
1919
|
2020
LL | pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
21-
| - let's call the lifetime of this reference `'1`
21+
| - - let's call the lifetime of this reference `'1`
22+
| |
23+
| binding `x` declared here
2224
LL | let y = &mut *x;
2325
| ------- borrow of `*x` occurs here
2426
LL | let z = x;
@@ -29,6 +31,8 @@ LL | y
2931
error[E0505]: cannot move out of `s` because it is borrowed
3032
--> $DIR/polonius-smoke-test.rs:42:5
3133
|
34+
LL | let s = &mut 1;
35+
| - binding `s` declared here
3236
LL | let r = &mut *s;
3337
| ------- borrow of `*s` occurs here
3438
LL | let tmp = foo(&r);

tests/ui/span/dropck-object-cycle.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0597]: `*m` does not live long enough
22
--> $DIR/dropck-object-cycle.rs:27:31
33
|
4+
LL | let m : Box<dyn Trait+'static> = make_val();
5+
| - binding `m` declared here
46
LL | assert_eq!(object_invoke1(&*m), (4,5));
57
| ^^^ borrowed value does not live long enough
68
...

tests/ui/span/regions-infer-borrow-scope-within-loop.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error[E0597]: `*x` does not live long enough
22
--> $DIR/regions-infer-borrow-scope-within-loop.rs:13:20
33
|
4+
LL | let x = make_box();
5+
| - binding `x` declared here
6+
...
47
LL | y = borrow(&*x);
58
| ^^^ borrowed value does not live long enough
69
...

tests/ui/span/send-is-not-static-std-sync.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error[E0505]: cannot move out of `y` because it is borrowed
22
--> $DIR/send-is-not-static-std-sync.rs:13:10
33
|
4+
LL | let y = Box::new(1);
5+
| - binding `y` declared here
6+
LL | let lock = Mutex::new(&x);
47
LL | *lock.lock().unwrap() = &*y;
58
| --- borrow of `*y` occurs here
69
LL | drop(y);
@@ -25,6 +28,9 @@ LL | lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z`
2528
error[E0505]: cannot move out of `y` because it is borrowed
2629
--> $DIR/send-is-not-static-std-sync.rs:27:10
2730
|
31+
LL | let y = Box::new(1);
32+
| - binding `y` declared here
33+
LL | let lock = RwLock::new(&x);
2834
LL | *lock.write().unwrap() = &*y;
2935
| --- borrow of `*y` occurs here
3036
LL | drop(y);
@@ -49,6 +55,9 @@ LL | lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z
4955
error[E0505]: cannot move out of `y` because it is borrowed
5056
--> $DIR/send-is-not-static-std-sync.rs:43:10
5157
|
58+
LL | let y = Box::new(1);
59+
| - binding `y` declared here
60+
...
5261
LL | tx.send(&*y);
5362
| --- borrow of `*y` occurs here
5463
LL | drop(y);

0 commit comments

Comments
 (0)