-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Elision in method can take 'static from self, perhaps surprising #48686
Copy link
Copy link
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
rustc currently compiles the following with no warnings or errors:
However, attempting to make this function safe reveals that the elided lifetime of
xisn't the lifetime in the return type-- it's instead copying over the'staticlifetime into the return type! Rustdoc actually documents that the signature of this method isfn get_mut(&'static self, x: &mut u8) -> &'static mut u8.The following code produces an error:
This seems like it could be fixed by disallowing elision in this case via a lint.
cc @aturon