Skip to content

Suggest blanket impls when implementing a trait for a trait #96076

Closed
@withoutboats

Description

@withoutboats

One of the big problems with the 2015-style trait object syntax (no dyn) was that users often write things like impl Iterator for MyTrait { } when what they really meant was impl<T: MyTrait> Iterator for T { }. Back then, the error message would more often than not be some inscrutable message about Sized, which would send them on a wild goose chase of adding Sized 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.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions