-
Notifications
You must be signed in to change notification settings - Fork 504
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09de1df
Add documentation for `#[diagnostic::do_not_recommend]`
weiznich 8c9da69
Merge branch 'master' into do_not_recommend
weiznich 3465b25
Update do_not_recommend docs
ehuss f28b8e8
Add missing period and do not wrap
ehuss 6fc4148
Some more elaboration on do_not_recommend
ehuss 341cc83
Soften the language to say "usually"
ehuss de346ad
Rewrite do_not_recommend example
ehuss e4c6263
usually to normally
ehuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
The attribute should be placed on a [trait implementation items]. It does not accept any arguments. If the attribute is placed in a wrong location or contains an unexpected argument the compiler might emit a warning and otherwise ignore the malformed part. | ||||||
|
||||||
In this example: | ||||||
|
||||||
```rust,compile_fail,E0277 | ||||||
trait Foo {} | ||||||
|
||||||
#[diagnostic::do_not_recommend] | ||||||
impl<T> Foo for T where T: Send {} | ||||||
|
||||||
fn needs_foo<T: Foo>() {} | ||||||
|
||||||
fn main() { | ||||||
needs_foo::<*mut ()>(); | ||||||
} | ||||||
|
||||||
``` | ||||||
|
||||||
the compiler may generate an error message which looks like this: | ||||||
|
||||||
```text | ||||||
error[E0277]: the trait bound `*mut (): Foo` is not satisfied | ||||||
--> $DIR/simple.rs:15:17 | ||||||
| | ||||||
LL | needs_foo::<*mut ()>(); | ||||||
| ^^^^^^^ the trait `Foo` is not implemented for `*mut ()` | ||||||
| | ||||||
note: required by a bound in `needs_foo` | ||||||
--> $DIR/simple.rs:10:17 | ||||||
| | ||||||
LL | fn needs_foo<T: Foo>() {} | ||||||
| ^^^ required by this bound in `needs_foo` | ||||||
|
||||||
error: aborting due to 1 previous error | ||||||
``` | ||||||
|
||||||
Without the attribute the compiler would complain about `*mut (): Send` instead. | ||||||
|
||||||
[Clippy]: https://github.com/rust-lang/rust-clippy | ||||||
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax | ||||||
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently this is mostly relevant for E0277, although that might change in the future?
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.