&str lifetime when variable is borrowed as argument (not captured) by closure
Open
Nobody has claimed this yet.
A-closures
A-higher-ranked
A-inference
A-lifetimes
C-bug
needs-triage
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
fn myfn(str: &str) {
let c = |s: &mut Option<&str>| *s = Some(str);
}
Compiler says
let c = |s: &mut Option<&str>| *s = Some(str);
| ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'static`
If I change the code to
fn myfn(str: &str) {
let mut var = None;
let c = || var = Some(str);
}
It compiles.
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
Start by compiling the two minimal examples centered on myfn, comparing the closure that takes s: &mut Option<&str> with the closure that captures var. Trace the compiler's lifetime treatment for these two closure forms; done means the reported inconsistency is explained and the borrow-checking behavior is corrected or documented by regression coverage.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100