-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Description
These cases, going by the way #42669 for one named and other anonymous lifetime parameter , the error message generated would suggest consider changing type of self
to &'a i32
. In the first case, this is fine but the second case, with self.field
not being the return value, the message is wrong and should only suggest changing the return type. We need to differentiate both the cases and fix the error message for the second case.
fn foo<'a>(&self, x: &'a i32) -> &i32 {
// Preferred message:
// fn foo<'a>(&self, x: &'a i32) -> &i32 {
// ----- ---- consider changing to `&'a i32`
// |
// consider changing to `&'a self`
if true { &self.field } else { x }
}
fn foo<'a>(&self, x: &'a i32) -> &i32 {
// preferred error
// fn foo<'a>(&self, x: &'a i32) -> &i32 {
// ---- consider changing to `&'a i32`
x
// error[E0611]: explicit lifetime required in the type of `self`
// |
// 33 | fn foo<'a>(&self, x: &'a i32) -> &i32 {
// | ^^^^^ consider changing the type of `self` to `&'a Foo`
// 34 | //
// 35 | x
// | - lifetime `'a` required
}
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics