Function arguments in nontrivial pattern can be reassigned with a different lifetime.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![allow(unused)]
fn works<'a, 'b>(mut x @ _: &'a i32, y: &'b i32) {
x = y;
}
fn fails<'a, 'b>(mut x: &'a i32, y: &'b i32) {
x = y;
}
I expected the two functions to either both compile or both error. Instead, only the first function compiles:
error: lifetime may not live long enough
--> src/lib.rs:8:5
|
7 | fn fails<'a, 'b>(mut x: &'a i32, y: &'b i32) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
8 | x = y;
| ^^^^^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
See also #128225, where a variable can be assigned a value with a different lifetime.
Related to https://github.com/rust-lang/rust/issues/148389, where a similar inconsistency occurs with async fn.
Meta
Reproducible on the playground with version 1.93.0-nightly (2025-11-02 b15a874aafe7eab9ea3a)
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 running the two functions in src/lib.rs on the cited Rust nightly playground version and compare the assignment diagnostics. Read the related issues #128225 and #148389 for the surrounding lifetime and async behavior. Done means the compiler's behavior for these equivalent argument patterns is made consistent, with appropriate regression coverage identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100