]> git.lizzy.rs Git - rust.git/commitdiff
Account for field access when looking for inner-most path in expression
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 02:47:50 +0000 (02:47 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 02:47:50 +0000 (02:47 +0000)
compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
tests/ui/borrowck/borrow-tuple-fields.stderr
tests/ui/borrowck/borrowck-field-sensitivity.stderr
tests/ui/borrowck/borrowck-local-borrow-with-panic-outlives-fn.stderr

index d60facb91b4553971d9c39f8a389f5a666c8fa3f..b6a676ef636904679ebdce8d0c4119f142117f34 100644 (file)
@@ -76,7 +76,8 @@ pub(crate) fn add_explanation_to_diagnostic(
                 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;
                     }
index befa751a6007b49c39a9530b025ccd59b7b46c75..d7d3efe492cef715f078077547b4df9193fd1081 100644 (file)
@@ -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;
index e009f5913edd072c2026c35721bb3edd000e6cf9..11812847dd1813a45c57ef9f15b332a66ae05776 100644 (file)
@@ -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 };
index 6ea6951ad966541eec0aeb987da3be4f35dba7ac..0fdb1dabbc50c21a5c5155ae04d3b1867435b2f1 100644 (file)
@@ -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);
    |     ----------^^^^^^^^-
    |     |         |