-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
In some cases, we can suggest the user add a where clause. This applies in cases where there are two named lifetimes already:
fn foo<'a, 'b>(mut x: Vec<&'a u32>, y: &'b u32) {
x.push(y);
}
fn main() { }
Here we currently print:
error[E0623]: lifetime mismatch
--> src/main.rs:2:12
|
1 | fn foo<'a, 'b>(mut x: Vec<&'a u32>, y: &'b u32) {
| ------- ------- these two types are declared with different lifetimes...
2 | x.push(y);
| ^ ...but data from `y` flows into `x` here
It'd be nice to add:
help: consider adding a where-clause like `where 'b: 'a`
Typically, we should only do this outside of trait impls, however, because otherwise the user may not be free to modify the signature. Or, if the trait is declared inside the same crate, we could find the corresponding method in the trait and add a note saying "the where-clause would also have to be added here" or some such thing.
alilleybrinker, estebank, dobkeratops and mark-i-mgaurikholkar-zz and estebank
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.