Closed
Description
e.g. in the test issue-36082.rs
:
rust/src/test/compile-fail/issue-36082.rs
Lines 1 to 25 in f6d7514
MIR borrowck currently emits the following errors:
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc ../src/test/compile-fail/issue-36082.rs -Z borrowck-mir
error[E0597]: borrowed value does not live long enough (Ast)
--> ../src/test/compile-fail/issue-36082.rs:18:31
|
18 | let val: &_ = x.borrow().0;
| ---------- ^ temporary value dropped here while still borrowed
| |
| temporary value created here
...
24 | }
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime
error[E0505]: cannot move out of `_` because it is borrowed (Mir)
--> ../src/test/compile-fail/issue-36082.rs:18:32
|
18 | let val: &_ = x.borrow().0;
| ---------- ^ move out of `_` occurs here
| |
| borrow of `_` occurs here
error[E0505]: cannot move out of `_` because it is borrowed (Mir)
--> ../src/test/compile-fail/issue-36082.rs:18:32
|
18 | let val: &_ = x.borrow().0;
| ---------- ^ move out of `_` occurs here
| |
| borrow of `_` occurs here
error[E0506]: cannot assign to `_` because it is borrowed (Mir)
--> ../src/test/compile-fail/issue-36082.rs:18:32
|
18 | let val: &_ = x.borrow().0;
| ---------- ^ assignment to borrowed `_` occurs here
| |
| borrow of `_` occurs here
The MIR borrowck errors are correctly detected when the MIR storagedead and drop conflict with the pre-existing borrow.
That is the exact definition of a "does not live long enough" error, so we need to detect this case and instead of showing multiple borrow errors, show a single "does not live long enough" error.