Skip to content

Commit c6111e8

Browse files
committed
Account for field access when looking for inner-most path in expression
1 parent be2ec32 commit c6111e8

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
7676
expr_finder.visit_expr(body.value);
7777
if let Some(mut expr) = expr_finder.result {
7878
while let hir::ExprKind::AddrOf(_, _, inner)
79-
| hir::ExprKind::Unary(hir::UnOp::Deref, inner) = &expr.kind
79+
| hir::ExprKind::Unary(hir::UnOp::Deref, inner)
80+
| hir::ExprKind::Field(inner, _) = &expr.kind
8081
{
8182
expr = inner;
8283
}

tests/ui/borrowck/borrow-tuple-fields.stderr

Lines changed: 4 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/borrow-tuple-fields.rs:12:13
33
|
4+
LL | let x: (Box<_>, _) = (Box::new(1), 2);
5+
| - binding `x` declared here
46
LL | let r = &x.0;
57
| ---- borrow of `x.0` occurs here
68
LL | let y = x;
@@ -32,6 +34,8 @@ LL | a.use_ref();
3234
error[E0505]: cannot move out of `x` because it is borrowed
3335
--> $DIR/borrow-tuple-fields.rs:28:13
3436
|
37+
LL | let x = Foo(Box::new(1), 2);
38+
| - binding `x` declared here
3539
LL | let r = &x.0;
3640
| ---- borrow of `x.0` occurs here
3741
LL | let y = x;

tests/ui/borrowck/borrowck-field-sensitivity.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ LL | let p = &x.b;
4141
error[E0505]: cannot move out of `x.b` because it is borrowed
4242
--> $DIR/borrowck-field-sensitivity.rs:34:10
4343
|
44+
LL | let x = A { a: 1, b: Box::new(2) };
45+
| - binding `x` declared here
4446
LL | let p = &x.b;
4547
| ---- borrow of `x.b` occurs here
4648
LL | drop(x.b);
@@ -51,6 +53,8 @@ LL | drop(**p);
5153
error[E0505]: cannot move out of `x.b` because it is borrowed
5254
--> $DIR/borrowck-field-sensitivity.rs:41:14
5355
|
56+
LL | let x = A { a: 1, b: Box::new(2) };
57+
| - binding `x` declared here
5458
LL | let p = &x.b;
5559
| ---- borrow of `x.b` occurs here
5660
LL | let _y = A { a: 3, .. x };

tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0597]: `z.1` does not live long enough
22
--> $DIR/borrowck-local-borrow-with-panic-outlives-fn.rs:3:15
33
|
4+
LL | let mut z = (0, 0);
5+
| ----- binding `z` declared here
46
LL | *x = Some(&mut z.1);
57
| ----------^^^^^^^^-
68
| | |

0 commit comments

Comments
 (0)