Diagnostics: suggest higher-rank trait bounds when implementing trait for &Type #69511
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Failing Code
Consider the following code:
playground
This fails with a pretty gnarly error about how
&IoArc<T>
doesn't have alifetime, parameter T doesn't live long enough, and we should consider adding
a lifetime. It (wrongly) suggest we may want to add a static lifetime. Which
is not the right solution.
Working Code
Instead the resolution is to add a higher-rank trait bound, like this:
Diagnostics Suggestions
I understand that this is not a particularly common pattern, but the compiler
really isn't of much help when trying to figure this out. A better suggestion
here would have been:
With if
'static
is sometimes the right solution, perhaps two help texts would make sense:The text was updated successfully, but these errors were encountered: