Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak E0597 #106897

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Account for * when looking for inner-most path in expression
  • Loading branch information
estebank committed Jan 17, 2023
commit be2ec32b18f7ad858dc746b26eb3a91a62a2c360
4 changes: 3 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/borrowck/borrowck-bad-nested-calls-move.stderr
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/borrowck/borrowck-move-mut-base-ptr.stderr
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/borrowck/borrowck-unary-move.stderr
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/nll/polonius/polonius-smoke-test.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/span/dropck-object-cycle.stderr
Original file line number Diff line number Diff line change
@@ -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
...
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/span/regions-infer-borrow-scope-within-loop.stderr
Original file line number Diff line number Diff line change
@@ -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
...
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/span/send-is-not-static-std-sync.stderr
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down