-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for #[diagnostic::do_not_recommend]
#1663
Conversation
src/attributes/diagnostics.md
Outdated
@@ -492,6 +492,47 @@ error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String` | |||
= note: Note 2 | |||
``` | |||
|
|||
### The `diagnostic::do_not_recommend` attribute | |||
|
|||
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to not show a certain trait implementation as part of the error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this explain a little more what error this is referring to, and what circumstances it will avoid showing an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this explain a little more what error this is referring to
Currently this is mostly relevant for E0277, although that might change in the future?
and what circumstances it will avoid showing an error?
It never avoids showing an error, it just changes the content of the error message to not mention/consider certain trait implementations if somewhat reasonable possible.
This comment has been minimized.
This comment has been minimized.
A few updates for the docs here: - Fix mistake using wrong attribute name - Add annotations - Try to clarify what kind of behavior the attribute has - Separate allowed-positions, and syntax as separate concerns.
@weiznich I was wondering if you could help me come up with a slightly more realistic example that demonstrates an improvement in the diagnostics? I feel like the example in the RFC at https://github.com/rust-lang/rfcs/blob/master/text/2397-do-not-recommend.md#guide-level-explanation is really close. It mentions "Perhaps when a function expects Bar and it's not implemented, it would never make sense to implement Foo for that type.", but I can't immediately think of an example where "it would never make sense to implement Foo". Is there maybe a way to relate the example to a realistic scenario? |
This adds some more explanation about the use of `diagnostic::do_not_recommend`, with the intent of helping the reader to understand how to use it. This also breaks that discussion out into a note. This also adds a before/after to the example to better show how it changes.
Specifically also, it would help to have a minimal self-contained example. |
The rustc test suite has several more relatistic examples:
Both examples are quite a bit larger than he trivial one, that's the reason why I've not used the here.
I think the wording is a bit too absolute here, in both cases linked above it's not that the suggested bound is never that one that the user want's. It's only that in almost all cases (for diesel something like >95%) the wrong suggestion that points users into the wrong direction. But there are edge cases where the current (without |
There may be times when the recommendation is useful, but the intent is to use the attribute when it usually is not.
This rewrites the example to use a more realistic example that actually demonstrates an improvement in the error message.
@weiznich Thanks! Both of those examples look pretty good, so I picked one that seemed like a pretty good demonstration. Does the current wording seem accurate to you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the more complex example. This sounds better now. I've left a minor comment about the wording otherwise this sounds good to me.
Co-authored-by: Georg Semmler <github@weiznich.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
src/attributes/diagnostics.md
Outdated
@@ -492,6 +492,47 @@ error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String` | |||
= note: Note 2 | |||
``` | |||
|
|||
### The `diagnostic::do_not_recommend` attribute | |||
|
|||
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to not show a certain trait implementation as part of the error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to not show a certain trait implementation as part of the error message. | |
The `#[diagnostic::do_not_recommend]` attribute is a hint to the compiler to not show a certain trait implementation as part of the error message. |
Documentation for rust-lang/rust#132056