Suggest blanket impls when implementing a trait for a trait #96076
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
E-mentor
Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
One of the big problems with the 2015-style trait object syntax (no
dyn
) was that users often write things likeimpl Iterator for MyTrait { }
when what they really meant wasimpl<T: MyTrait> Iterator for T { }
. Back then, the error message would more often than not be some inscrutable message aboutSized
, which would send them on a wild goose chase of addingSized
bounds everywhere they could think of, leading to even more inscrutable messages.Now, the error message is clearer: it tells users they need to add
dyn
for a trait object type. However, I find in many cases (most cases?) this is not what users actually want - what they actually want is the blanket impl. It would be helpful to have a note suggesting the correct syntax for a blanket impl, or better yet just presenting both correct syntaxes (impl for trait object and blanket impl) on equal footing and making it clear the difference between them.The text was updated successfully, but these errors were encountered: