traits icon indicating copy to clipboard operation
traits copied to clipboard

Use `diagnostic::on_unimplemented` to improve blanket impl debugging

Open tarcieri opened this issue 1 year ago • 3 comments

Rust 1.78 added a new diagnostic::on_unimplemented attribute which can be used to add additional context in the event a trait isn't impl'd in the form of note messages that appear in the diagnostics:

https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html#guide-level-explanation

These seem very helpful for improving debugging of missing trait impls which are expected to be received via a blanket impl, i.e. the note can include the name of the other trait the user is expected to implement.

It will be awhile before we can consider Rust 1.78, however I thought I'd go ahead and open this as a tracking / planning issue for using this feature.

tarcieri avatar May 03 '24 14:05 tarcieri

Actually, is it a problem to go ahead and start using this now? It's just an attribute, so older Rust versions should ignore it, right?

tarcieri avatar May 03 '24 14:05 tarcieri

Unfortunately, no, it will result in "error[E0658]: #[diagnostic] attribute name space is experimental" compilation error or "error[E0433]: failed to resolve: use of undeclared type or module diagnostic" on older Rust versions.

newpavlov avatar May 03 '24 14:05 newpavlov

With recent MSRV bumps / plans to bump MSRV, we can start considering this

tarcieri avatar Sep 26 '24 17:09 tarcieri