Repository navigation
Add some documentation around the #[diagnostic::on_unknown] attribute
#2379
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
Open
weiznich
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
weiznich:on_unknown
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -743,6 +743,92 @@ error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied | |||||
|
|
||||||
| The first error message includes a somewhat confusing error message about the relationship of `&str` and `Expression`, as well as the unsatisfied trait bound in the blanket impl. After adding `#[diagnostic::do_not_recommend]`, it no longer considers the blanket impl for the recommendation. The message should be a little clearer, with an indication that a string cannot be converted to an `Integer`. | ||||||
|
|
||||||
| r[attributes.diagnostic.on_unknown] | ||||||
| ### The `diagnostic::on_unknown` attribute | ||||||
|
|
||||||
| The `#[diagnostic::on_unknown]` attribute should be | ||||||
| placed on use and module declarations, though it is not an error to be located in other | ||||||
| positions. This attribute is a hint to the compiler to supplement the error message when the | ||||||
| annotated declaration is involved in a name resolution error. | ||||||
|
|
||||||
| Format parameters with the given named parameter will be replaced with the following text: | ||||||
|
|
||||||
| - `{Unresolved}` — The `SimplePathSegment` of the import path that could not be resolved. | ||||||
| - `{This}` — The name of the annotated item. On `use` statements this is identical to `{Unresolved}`. | ||||||
|
|
||||||
| The original error message will not be suppressed but is emitted as a note instead. | ||||||
|
|
||||||
| #### On use declarations | ||||||
|
|
||||||
| ```rust,edition2018,compile_fail,E0432 | ||||||
| #[diagnostic::on_unknown( | ||||||
| message = "`{Unresolved}` doesn't exist", | ||||||
| label = "you did something silly here" | ||||||
| )] | ||||||
| use doesnt_exist; | ||||||
|
Contributor
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. the missing apostrophe in "doesn't" makes this a bit hard to read - maybe |
||||||
| ``` | ||||||
| This will result in the following error: | ||||||
| ```text | ||||||
| error[E0432]: `doesnt_exist` doesn't exist | ||||||
| --> src/lib.rs:7:5 | ||||||
| | | ||||||
| 7 | use doesnt_exist; | ||||||
| | ^^^^^^^^^^^^ you did something silly here | ||||||
| | | ||||||
| = note: unresolved import `doesnt_exist` | ||||||
|
|
||||||
| For more information about this error, try `rustc --explain E0432`. | ||||||
| ``` | ||||||
|
|
||||||
| #### On module declarations | ||||||
|
|
||||||
| ```rust,edition2018,compile_fail,E0432 | ||||||
| #[diagnostic::on_unknown( | ||||||
| message = "module `{This}` is empty, there is no `{Unresolved}` here", | ||||||
| label = "can't import something from an empty module" | ||||||
| )] | ||||||
| mod empty {} | ||||||
|
|
||||||
| use empty::what; | ||||||
| ``` | ||||||
| This will result in the following error: | ||||||
|
|
||||||
| ```text | ||||||
| error[E0432]: module `empty` is empty, there is no `what` here | ||||||
| --> src/lib.rs:9:5 | ||||||
| | | ||||||
| 9 | use empty::what; | ||||||
| | ^^^^^^^---- | ||||||
| | | | ||||||
| | can't import something from an empty module | ||||||
| | | ||||||
| = note: unresolved import `empty::what` | ||||||
| ``` | ||||||
|
|
||||||
| ### Edition differences | ||||||
|
|
||||||
| In the 2015 edition, use paths are relative to the crate root. For example, `use empty` will be resolved relative to the crate root and resolution will not encounter the `mod empty {}` declaration. | ||||||
|
Contributor
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
|
||||||
| ```rust,edition2015,compile_fail,E0432 | ||||||
| #![feature(diagnostic_on_unknown)] | ||||||
|
|
||||||
| mod foo { | ||||||
| #[diagnostic::on_unknown(message = "oh oh")] | ||||||
| mod empty {} | ||||||
|
|
||||||
| use empty::what; | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ```text | ||||||
| error[E0432]: unresolved import `empty` | ||||||
| --> src/main.rs:9:8 | ||||||
| | | ||||||
| 9 | use empty::what; | ||||||
| | ^^^^^ | ||||||
| | | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| [Clippy]: https://github.com/rust-lang/rust-clippy | ||||||
| [`Drop`]: ../special-types-and-traits.md#drop | ||||||
| [`unsafe` blocks]: ../expressions/block-expr.md#unsafe-blocks | ||||||
|
|
||||||
Oops, something went wrong.
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.
the reference no longer breaks paragraphs across multiple lines in the markdown, please unwrap the paragraphs