Idea: Recommend types when trait bounds are not satisfied

Consider giving crate authors a way to recommend types when trait bound not satisfied happens for recommending common practices. This will make crate users' day a bit easier I suppose.

Where would this recommendation be introduced? What traits would this be for? Most importantly, can you provide an example of how this would actually work?

I think we can put them on top of where keyword, just like how we document for functions. And the recommendation could be added on top of existing errors, like consider giving it a type or consider further restricting the generics with..... sort of thing. I'm sorry that I cannot provide a working example because that's way beyond my capabilities.

The compiler already has an internal feature for this, called rustc_on_unimplemented. It can only be used by the standard library, and it is responsible for various specialized errors such as when you use ? inside a function that returns ().

If you search for that name you will find a few previous discussions about how to make it a stable feature for any crate to use.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.