Missing lifetimes needed in impl
item don't have enough help for newcomer devs
#135589
Open
1 of 9 tasks
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lifetimes
Area: Lifetimes / regions
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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
impl
if 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 IntoIter
if 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
impl
has lifetimes, the above should suggest using that lifetime.Currently the documentation of
E0261
mentions a similar enough case, butE0207
doesn'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 theimpl
if the trait or self type have anon lifetimestype NoLt<'a> = TypeMissingLt<'a>;
, suggest removing the lifetime from thetype
if theimpl
has a named lifetimetype NoLt = TypeMissingLt<'a>;
, suggest adding'a
to theimpl
if the trait or self type have anon lifetimesimpl<'a> IntoIterator for &S
, suggest changing the self type to&'a S
type NoLt = &T;
, ifimpl
has a lifetime suggest using thattype NoLt = &T;
, suggest using a named lifetime from theimpl
if presenttype NoLt = &T;
, suggest adding'a
to theimpl
if the trait or self type have anon lifetimesE0207
to mention these casesThe text was updated successfully, but these errors were encountered: