So I've done a little research and come upon the following:
-
rustc_on_unimplemented
- this is an attribute that lets the error when using an unimplemented trait to be tweaked by the trait definition itself. As implied by therustc_
prefix it's meant for compiler use only. - A way to customize Rust error messages - this post suggests writing a tool to parse Rust error messages and then emit new, more helpful and library specific error messages.
After thinking about this for a bit, I have the following thoughts:
- The scenario that first prompted down this rabbit hole was figuring out if there was a way to generate better error messages for type safe builder methods. Type safe builders make heavy use of generics + structs, and most methods for the structs are limited to certain combinations of type parameters. If we extended rustc_on_unimplemented to work with impl blocks of structs, not just trait definitions, that'd fill this use case (provided we stabilized it too, which would be a lot of work) - I could customize the unimplemented error for the setters to say that the value was already set.
- Besides type safe builders, the other places where errors fall flat are things with complex type signature mismatches, and it seem like rustc_on_implemented isn't quite powerful enough to give truly nice error messages - the diesel example from the referenced blog post is a good example.
Is there any work being done on pursuing these ideas? It seems like any way to trigger stable emissions of full type signatures for method not implemented for type xxx because of bound yyy
with full type paths in the error information would be a good start.