You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Triggers on code of the form &'a mut Something<'a>. (The mut is important here.) I see people write this when they're not sure what to put in each lifetime position, but it's (as far as I can tell!) basically always wrong, and causes weird lifetime errors in other places by unifying the two lifetimes. This is particularly annoying when it appears as a function argument, as it causes weird errors in the caller.
Unless I've missed something this code should almost always be &'b mut Something<'a> instead.
You'd probably also want this to point out cases of &'a mut &'a Something.
Advantage
Avoids unifying the invariant lifetime of the mut reference with the (often covariant) lifetime of the (often not mut) reference inside the parameterized type.
More importantly, avoids distant confusing errors from rustc attempting to solve lifetime constraints in callers.
Drawbacks
It's possible that this pattern has a use and I've never seen it -- if it does, this would false positive on such code.
Example
&'a mutSomething<'a>
Could be written as:
&'b mutSomething<'a>
The text was updated successfully, but these errors were encountered:
What it does
Triggers on code of the form
&'a mut Something<'a>
. (Themut
is important here.) I see people write this when they're not sure what to put in each lifetime position, but it's (as far as I can tell!) basically always wrong, and causes weird lifetime errors in other places by unifying the two lifetimes. This is particularly annoying when it appears as a function argument, as it causes weird errors in the caller.Unless I've missed something this code should almost always be
&'b mut Something<'a>
instead.You'd probably also want this to point out cases of
&'a mut &'a Something
.Advantage
Avoids unifying the invariant lifetime of the
mut
reference with the (often covariant) lifetime of the (often notmut
) reference inside the parameterized type.More importantly, avoids distant confusing errors from rustc attempting to solve lifetime constraints in callers.
Drawbacks
It's possible that this pattern has a use and I've never seen it -- if it does, this would false positive on such code.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: