about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-01-17 02:47:50 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-01-17 02:47:50 +0000
commitc6111e8d232964f11eb3540ed7228de6e13782df (patch)
tree28a42f1479bda1307b5a77de0848eb312e339293
parentbe2ec32b18f7ad858dc746b26eb3a91a62a2c360 (diff)
downloadrust-c6111e8d232964f11eb3540ed7228de6e13782df.tar.gz
rust-c6111e8d232964f11eb3540ed7228de6e13782df.zip
Account for field access when looking for inner-most path in expression
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs3
-rw-r--r--tests/ui/borrowck/borrow-tuple-fields.stderr4
-rw-r--r--tests/ui/borrowck/borrowck-field-sensitivity.stderr4
-rw-r--r--tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr2
4 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
index d60facb91b4..b6a676ef636 100644
--- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
@@ -76,7 +76,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
                 expr_finder.visit_expr(body.value);
                 if let Some(mut expr) = expr_finder.result {
                     while let hir::ExprKind::AddrOf(_, _, inner)
-                        | hir::ExprKind::Unary(hir::UnOp::Deref, inner) = &expr.kind
+                        | hir::ExprKind::Unary(hir::UnOp::Deref, inner)
+                        | hir::ExprKind::Field(inner, _) = &expr.kind
                     {
                         expr = inner;
                     }
diff --git a/tests/ui/borrowck/borrow-tuple-fields.stderr b/tests/ui/borrowck/borrow-tuple-fields.stderr
index befa751a600..d7d3efe492c 100644
--- a/tests/ui/borrowck/borrow-tuple-fields.stderr
+++ b/tests/ui/borrowck/borrow-tuple-fields.stderr
@@ -1,6 +1,8 @@
 error[E0505]: cannot move out of `x` because it is borrowed
   --> $DIR/borrow-tuple-fields.rs:12:13
    |
+LL |     let x: (Box<_>, _) = (Box::new(1), 2);
+   |         - binding `x` declared here
 LL |     let r = &x.0;
    |             ---- borrow of `x.0` occurs here
 LL |     let y = x;
@@ -32,6 +34,8 @@ LL |     a.use_ref();
 error[E0505]: cannot move out of `x` because it is borrowed
   --> $DIR/borrow-tuple-fields.rs:28:13
    |
+LL |     let x = Foo(Box::new(1), 2);
+   |         - binding `x` declared here
 LL |     let r = &x.0;
    |             ---- borrow of `x.0` occurs here
 LL |     let y = x;
diff --git a/tests/ui/borrowck/borrowck-field-sensitivity.stderr b/tests/ui/borrowck/borrowck-field-sensitivity.stderr
index e009f5913ed..11812847dd1 100644
--- a/tests/ui/borrowck/borrowck-field-sensitivity.stderr
+++ b/tests/ui/borrowck/borrowck-field-sensitivity.stderr
@@ -41,6 +41,8 @@ LL |     let p = &x.b;
 error[E0505]: cannot move out of `x.b` because it is borrowed
   --> $DIR/borrowck-field-sensitivity.rs:34:10
    |
+LL |     let x = A { a: 1, b: Box::new(2) };
+   |         - binding `x` declared here
 LL |     let p = &x.b;
    |             ---- borrow of `x.b` occurs here
 LL |     drop(x.b);
@@ -51,6 +53,8 @@ LL |     drop(**p);
 error[E0505]: cannot move out of `x.b` because it is borrowed
   --> $DIR/borrowck-field-sensitivity.rs:41:14
    |
+LL |     let x = A { a: 1, b: Box::new(2) };
+   |         - binding `x` declared here
 LL |     let p = &x.b;
    |             ---- borrow of `x.b` occurs here
 LL |     let _y = A { a: 3, .. x };
diff --git a/tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr b/tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr
index 6ea6951ad96..0fdb1dabbc5 100644
--- a/tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr
+++ b/tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr
@@ -1,6 +1,8 @@
 error[E0597]: `z.1` does not live long enough
   --> $DIR/borrowck-local-borrow-with-panic-outlives-fn.rs:3:15
    |
+LL |     let mut z = (0, 0);
+   |         ----- binding `z` declared here
 LL |     *x = Some(&mut z.1);
    |     ----------^^^^^^^^-
    |     |         |