-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Missing lifetimes needed in impl item don't have enough help for newcomer devs #135589
Copy link
Copy link
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`P-lowLow priorityLow priorityT-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-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`P-lowLow priorityLow priorityT-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.
If you write like
you get the following errors
ignoring the first one for now, if you follow the suggestion you get
Both of these cases should instead mention likely adding the lifetime to the
implif either the trait or the self type have any lifetimes, named or anon. We should mention that the<'a>should be removed to match the def, and point at the def if local to modify it to add it to the trait.If we don't add the
<'a>to thetype IntoIter, we get something closer to what we want:We shouldn't be suggesting modifying
type IntoIterif we can know that the trait definition didn't have named lifetimes.If we add
impl<'a>, then we get a very terse output:This should look at the trait and self type and see if there is any anon lifetime at play, and suggest using the named lifetime there. In this case,
&'a S.In all of these cases we still get:
When
implhas lifetimes, the above should suggest using that lifetime.Currently the documentation of
E0261mentions a similar enough case, butE0207doesn't. We'd likely want to add a mention about lifetimes in the latter.Inspired by mainmatter/100-exercises-to-learn-rust#245
type NoLt = TypeMissingLt;, do not suggesttype NoLt<'a> = TypeMisingLt<'a>;if the trait doesn't accept ittype NoLt = TypeMissingLt;, suggest adding a lifetime to theimplif the trait or self type have anon lifetimestype NoLt<'a> = TypeMissingLt<'a>;, suggest removing the lifetime from thetypeif theimplhas a named lifetimetype NoLt = TypeMissingLt<'a>;, suggest adding'ato theimplif the trait or self type have anon lifetimesimpl<'a> IntoIterator for &S, suggest changing the self type to&'a Stype NoLt = &T;, ifimplhas a lifetime suggest using thattype NoLt = &T;, suggest using a named lifetime from theimplif presenttype NoLt = &T;, suggest adding'ato theimplif the trait or self type have anon lifetimesE0207to mention these cases