]> git.lizzy.rs Git - rust.git/commitdiff
Account for method call and indexing when looking for inner-most path in expression
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 02:52:43 +0000 (02:52 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 02:52:43 +0000 (02:52 +0000)
14 files changed:
compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
tests/ui/box/leak-alloc.stderr
tests/ui/dropck/drop-with-active-borrows-1.stderr
tests/ui/generator/dropck.stderr
tests/ui/issues/issue-52126-assign-op-invariance.stderr
tests/ui/macros/format-args-temporaries-in-write.stderr
tests/ui/match/issue-74050-end-span.stderr
tests/ui/moves/move-fn-self-receiver.stderr
tests/ui/nll/issue-54556-niconii.stderr
tests/ui/span/borrowck-let-suggestion-suffixes.rs
tests/ui/span/borrowck-let-suggestion-suffixes.stderr
tests/ui/span/destructor-restrictions.stderr
tests/ui/span/issue-23338-locals-die-before-temps-of-body.stderr
tests/ui/span/issue-40157.stderr

index b6a676ef636904679ebdce8d0c4119f142117f34..19855075ced80d7383d01be49f5d4e5dc946aedd 100644 (file)
@@ -77,7 +77,9 @@ pub(crate) fn add_explanation_to_diagnostic(
                 if let Some(mut expr) = expr_finder.result {
                     while let hir::ExprKind::AddrOf(_, _, inner)
                         | hir::ExprKind::Unary(hir::UnOp::Deref, inner)
-                        | hir::ExprKind::Field(inner, _) = &expr.kind
+                        | hir::ExprKind::Field(inner, _)
+                        | hir::ExprKind::MethodCall(_, inner, _, _)
+                        | hir::ExprKind::Index(inner, _) = &expr.kind
                     {
                         expr = inner;
                     }
index e8a6ad0995a0fa555fdd21ac4cfb519d89d9a4f0..5140b58934a5cf34467d7f02ece576f315ba09e2 100644 (file)
@@ -1,6 +1,8 @@
 error[E0505]: cannot move out of `alloc` because it is borrowed
   --> $DIR/leak-alloc.rs:26:10
    |
+LL |     let alloc = Alloc {};
+   |         ----- binding `alloc` declared here
 LL |     let boxed = Box::new_in(10, alloc.by_ref());
    |                                 -------------- borrow of `alloc` occurs here
 LL |     let theref = Box::leak(boxed);
index 8d6a7f3721f0fab6e3431921ca493329585b4325..4585b22974cdbc91ae3f80dfaef8ae88853f34a7 100644 (file)
@@ -1,6 +1,8 @@
 error[E0505]: cannot move out of `a` because it is borrowed
   --> $DIR/drop-with-active-borrows-1.rs:4:10
    |
+LL |     let a = "".to_string();
+   |         - binding `a` declared here
 LL |     let b: Vec<&str> = a.lines().collect();
    |                        --------- borrow of `a` occurs here
 LL |     drop(a);
index 7bb188352d7a27b7631deb78e7b5fe20194c3377..b9a3a124acb61d91be4246ad201094fdbf452786 100644 (file)
@@ -1,6 +1,9 @@
 error[E0597]: `*cell` does not live long enough
   --> $DIR/dropck.rs:10:40
    |
+LL |     let (mut gen, cell);
+   |                   ---- binding `cell` declared here
+LL |     cell = Box::new(RefCell::new(0));
 LL |     let ref_ = Box::leak(Box::new(Some(cell.borrow_mut())));
    |                                        ^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
 ...
index d450675776268221c33639a0501498cbbe1015ea..2d3b48832c527c83f1c878d47636ac4f887b3da7 100644 (file)
@@ -1,6 +1,8 @@
 error[E0597]: `line` does not live long enough
   --> $DIR/issue-52126-assign-op-invariance.rs:34:28
    |
+LL |     for line in vec!["123456789".to_string(), "12345678".to_string()] {
+   |         ---- binding `line` declared here
 LL |         let v: Vec<&str> = line.split_whitespace().collect();
    |                            ^^^^^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
 ...
index 287cd7d67044eb824eba79c53b7c89130d356c27..520b2ce50526f9044cd5e720c270038beb453a86 100644 (file)
@@ -1,6 +1,8 @@
 error[E0597]: `mutex` does not live long enough
   --> $DIR/format-args-temporaries-in-write.rs:41:27
    |
+LL |         let mutex = Mutex;
+   |             ----- binding `mutex` declared here
 LL |         write!(Out, "{}", mutex.lock()) /* no semicolon */
    |                           ^^^^^^^^^^^^
    |                           |
@@ -16,6 +18,8 @@ LL |     };
 error[E0597]: `mutex` does not live long enough
   --> $DIR/format-args-temporaries-in-write.rs:47:29
    |
+LL |         let mutex = Mutex;
+   |             ----- binding `mutex` declared here
 LL |         writeln!(Out, "{}", mutex.lock()) /* no semicolon */
    |                             ^^^^^^^^^^^^
    |                             |
index 59c091e44eb87efa0e16a1111eab535d3618a5e9..0b3425f2b1a1cec9ffa14bf5c5a606d3cb9bf5ed 100644 (file)
@@ -4,6 +4,7 @@ error[E0597]: `arg` does not live long enough
 LL |     let _arg = match args.next() {
    |         ---- borrow later stored here
 LL |         Some(arg) => {
+   |              --- binding `arg` declared here
 LL |             match arg.to_str() {
    |                   ^^^^^^^^^^^^ borrowed value does not live long enough
 ...
index 7f69e5dcfb784db1ea80cf0b567fe483007f5bc6..91d237b1d1a9085273d9778e9850ecc101c5423c 100644 (file)
@@ -75,6 +75,8 @@ LL |     fn use_pin_box_self(self: Pin<Box<Self>>) {}
 error[E0505]: cannot move out of `mut_foo` because it is borrowed
   --> $DIR/move-fn-self-receiver.rs:50:5
    |
+LL |     let mut mut_foo = Foo;
+   |         ----------- binding `mut_foo` declared here
 LL |     let ret = mut_foo.use_mut_self();
    |               ---------------------- borrow of `mut_foo` occurs here
 LL |     mut_foo;
index a8e1edc5497422311da7754564e32d8c29978c78..d41d462f2bcb0130bc4f032ddf223b7d3b29bd87 100644 (file)
@@ -1,6 +1,9 @@
 error[E0597]: `counter` does not live long enough
   --> $DIR/issue-54556-niconii.rs:22:20
    |
+LL |     let counter = Mutex;
+   |         ------- binding `counter` declared here
+LL |
 LL |     if let Ok(_) = counter.lock() { }
    |                    ^^^^^^^^^^^^^^
    |                    |
index 18abfb5c3fbecb2c589e7bde35cc77e7b7008895..ad556f281df126b5b48419044847fbd44d2ef781 100644 (file)
@@ -8,6 +8,7 @@ fn f() {
 
     {
         let young = ['y'];       // statement 3
+        //~^ NOTE binding `young` declared here
 
         v2.push(&young[0]);      // statement 4
         //~^ ERROR `young[_]` does not live long enough
index 2dc29a78d204d15a35b4e55818b8e29f76c8e6d3..545b235a552d18986f6810756dc92d5c330860bb 100644 (file)
@@ -1,6 +1,9 @@
 error[E0597]: `young[_]` does not live long enough
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:12:17
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:13:17
    |
+LL |         let young = ['y'];       // statement 3
+   |             ----- binding `young` declared here
+...
 LL |         v2.push(&young[0]);      // statement 4
    |                 ^^^^^^^^^ borrowed value does not live long enough
 ...
@@ -11,7 +14,7 @@ LL |     (v1, v2, v3, /* v4 is above. */ v5).use_ref();
    |          -- borrow later used here
 
 error[E0716]: temporary value dropped while borrowed
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:19:14
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:20:14
    |
 LL |     v3.push(&id('x'));           // statement 6
    |              ^^^^^^^ - temporary value is freed at the end of this statement
@@ -28,7 +31,7 @@ LL ~     v3.push(&binding);           // statement 6
    |
 
 error[E0716]: temporary value dropped while borrowed
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:29:18
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:30:18
    |
 LL |         v4.push(&id('y'));
    |                  ^^^^^^^ - temporary value is freed at the end of this statement
@@ -41,7 +44,7 @@ LL |         v4.use_ref();
    = note: consider using a `let` binding to create a longer lived value
 
 error[E0716]: temporary value dropped while borrowed
-  --> $DIR/borrowck-let-suggestion-suffixes.rs:40:14
+  --> $DIR/borrowck-let-suggestion-suffixes.rs:41:14
    |
 LL |     v5.push(&id('z'));
    |              ^^^^^^^ - temporary value is freed at the end of this statement
index 53c9404620f35d8633354a9eb9a113352852fe9d..281248626c82609a881e1caff5b1ce56b9bb3de5 100644 (file)
@@ -1,6 +1,8 @@
 error[E0597]: `*a` does not live long enough
   --> $DIR/destructor-restrictions.rs:8:10
    |
+LL |         let a = Box::new(RefCell::new(4));
+   |             - binding `a` declared here
 LL |         *a.borrow() + 1
    |          ^^^^^^^^^^
    |          |
index 3c2022748f0944339f99e3560083a49cd3cf1f7c..e1a377203e2962551a4d7425ac5cb630201961e7 100644 (file)
@@ -1,6 +1,8 @@
 error[E0597]: `y` does not live long enough
   --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:10:5
    |
+LL |     let y = x;
+   |         - binding `y` declared here
 LL |     y.borrow().clone()
    |     ^^^^^^^^^^
    |     |
@@ -22,6 +24,8 @@ LL |     let x = y.borrow().clone(); x
 error[E0597]: `y` does not live long enough
   --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:17:9
    |
+LL |         let y = x;
+   |             - binding `y` declared here
 LL |         y.borrow().clone()
    |         ^^^^^^^^^^
    |         |
index e9b84de5059892d20ff3ddd498d6090271c9e998..a0afd33f7c7c4c941616bf1b772a47fe775f53b4 100644 (file)
@@ -2,9 +2,10 @@ error[E0597]: `foo` does not live long enough
   --> $DIR/issue-40157.rs:2:53
    |
 LL |     {println!("{:?}", match { let foo = vec![1, 2]; foo.get(1) } { x => x });}
-   |                                                     ^^^^^^^^^^ - `foo` dropped here while still borrowed
-   |                                                     |
-   |                                                     borrowed value does not live long enough
+   |                                   ---               ^^^^^^^^^^ - `foo` dropped here while still borrowed
+   |                                   |                 |
+   |                                   |                 borrowed value does not live long enough
+   |                                   binding `foo` declared here
 
 error: aborting due to previous error