Account for method call and indexing when looking for inner-most path in expression

This commit is contained in:
Esteban Küber 2023-01-17 02:52:43 +00:00
parent c6111e8d23
commit 7b8251e188
14 changed files with 40 additions and 8 deletions

View File

@ -77,7 +77,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
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;
}

View 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);

View 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);

View 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
...

View 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
...

View 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 */
| ^^^^^^^^^^^^
| |

View 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
...

View 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;

View 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() { }
| ^^^^^^^^^^^^^^
| |

View 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

View 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

View 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
| ^^^^^^^^^^
| |

View 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()
| ^^^^^^^^^^
| |

View 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