Account for `*` when looking for inner-most path in expression

This commit is contained in:
Esteban Küber 2023-01-17 02:45:11 +00:00
parent e4f61afa77
commit be2ec32b18
8 changed files with 31 additions and 2 deletions

View File

@ -75,7 +75,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(body.value);
if let Some(mut expr) = expr_finder.result {
while let hir::ExprKind::AddrOf(_, _, inner) = &expr.kind {
while let hir::ExprKind::AddrOf(_, _, inner)
| hir::ExprKind::Unary(hir::UnOp::Deref, inner) = &expr.kind
{
expr = inner;
}
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind

View File

@ -1,6 +1,9 @@
error[E0505]: cannot move out of `a` because it is borrowed
--> $DIR/borrowck-bad-nested-calls-move.rs:25:9
|
LL | let mut a: Box<_> = Box::new(1);
| ----- binding `a` declared here
...
LL | add(
| --- borrow later used by call
LL | &*a,
@ -11,6 +14,8 @@ LL | a);
error[E0505]: cannot move out of `a` because it is borrowed
--> $DIR/borrowck-bad-nested-calls-move.rs:32:9
|
LL | let mut a: Box<_> = Box::new(1);
| ----- binding `a` declared here
LL | add(
| --- borrow later used by call
LL | &*a,

View File

@ -1,6 +1,8 @@
error[E0505]: cannot move out of `t0` because it is borrowed
--> $DIR/borrowck-move-mut-base-ptr.rs:10:14
|
LL | fn foo(t0: &mut isize) {
| -- binding `t0` declared here
LL | let p: &isize = &*t0; // Freezes `*t0`
| ---- borrow of `*t0` occurs here
LL | let t1 = t0;

View File

@ -1,6 +1,8 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrowck-unary-move.rs:3:10
|
LL | fn foo(x: Box<isize>) -> isize {
| - binding `x` declared here
LL | let y = &*x;
| --- borrow of `*x` occurs here
LL | free(x);

View File

@ -18,7 +18,9 @@ error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/polonius-smoke-test.rs:18:13
|
LL | pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
| - let's call the lifetime of this reference `'1`
| - - let's call the lifetime of this reference `'1`
| |
| binding `x` declared here
LL | let y = &mut *x;
| ------- borrow of `*x` occurs here
LL | let z = x;
@ -29,6 +31,8 @@ LL | y
error[E0505]: cannot move out of `s` because it is borrowed
--> $DIR/polonius-smoke-test.rs:42:5
|
LL | let s = &mut 1;
| - binding `s` declared here
LL | let r = &mut *s;
| ------- borrow of `*s` occurs here
LL | let tmp = foo(&r);

View File

@ -1,6 +1,8 @@
error[E0597]: `*m` does not live long enough
--> $DIR/dropck-object-cycle.rs:27:31
|
LL | let m : Box<dyn Trait+'static> = make_val();
| - binding `m` declared here
LL | assert_eq!(object_invoke1(&*m), (4,5));
| ^^^ borrowed value does not live long enough
...

View File

@ -1,6 +1,9 @@
error[E0597]: `*x` does not live long enough
--> $DIR/regions-infer-borrow-scope-within-loop.rs:13:20
|
LL | let x = make_box();
| - binding `x` declared here
...
LL | y = borrow(&*x);
| ^^^ borrowed value does not live long enough
...

View File

@ -1,6 +1,9 @@
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/send-is-not-static-std-sync.rs:13:10
|
LL | let y = Box::new(1);
| - binding `y` declared here
LL | let lock = Mutex::new(&x);
LL | *lock.lock().unwrap() = &*y;
| --- borrow of `*y` occurs here
LL | drop(y);
@ -25,6 +28,9 @@ LL | lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z`
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/send-is-not-static-std-sync.rs:27:10
|
LL | let y = Box::new(1);
| - binding `y` declared here
LL | let lock = RwLock::new(&x);
LL | *lock.write().unwrap() = &*y;
| --- borrow of `*y` occurs here
LL | drop(y);
@ -49,6 +55,9 @@ LL | lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/send-is-not-static-std-sync.rs:43:10
|
LL | let y = Box::new(1);
| - binding `y` declared here
...
LL | tx.send(&*y);
| --- borrow of `*y` occurs here
LL | drop(y);