Borrowcheck error with `break` blames trailing expression for borrowing
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![allow(unreachable_code)]
pub fn foo() {
let _x = 'a: {
if true {
break 'a &1;
}
let temp = 1;
break 'a &temp;
panic!()
};
}
Current output
error[E0597]: `temp` does not live long enough
--> src/lib.rs:9:18
|
8 | let temp = 1;
| ---- binding `temp` declared here
9 | break 'a &temp;
| ^^^^^ borrowed value does not live long enough
10 | panic!()
| -------- borrow later used here
11 | };
| - `temp` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
Don't point to the panic.
Rationale and extra context
No response
Other cases
Rust Version
Reproducible on the playground with version 1.91.0-nightly (2025-08-16 2e2642e641a941f0a140)
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the borrow-checker diagnostic from the provided Rust snippet on the playground with Rust 1.91.0-nightly (2025-08-16). Compare the current and desired diagnostics, with completion indicated when the trailing panic!() is no longer identified as the later borrow use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100