-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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 #148389, where a similar inconsistency occurs with async fn.
Meta
Reproducible on the playground with version 1.93.0-nightly (2025-11-02 b15a874aafe7eab9ea3a)
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.