-
Notifications
You must be signed in to change notification settings - Fork 498
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 the #[diagnostic]
attribute namespace and the #[diagnostic::on_unimplemented]
feature to the reference
#1449
Conversation
6bfddc2
to
d362a05
Compare
I'm not really sure what needs to be done to address the CI errors as the name space is in fact currently unstable but it was requested during the stablization PR to fill this PR. |
The CI errors are fine, this won't be merged until the stabilization hits nightly which should resolve them. |
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
@@ -301,6 +301,60 @@ When used on a function in a trait implementation, the attribute does nothing. | |||
> let _ = five(); | |||
> ``` | |||
|
|||
## The `diagnostic` tool attribute namespace | |||
|
|||
The `#[diagnostic]` attribute namespace is meant to provide a home for attribute that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working. |
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.
We try to avoid using the phrase "the compiler" too much, since the reference is really focused on the language and not how it is implemented. There are also ambiguities to be careful of in terms of wording things like "user" or "error".
The `#[diagnostic]` attribute namespace is meant to provide a home for attribute that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working. | |
The `#[diagnostic]` attribute namespace is meant to provide a home for attributes to influence compile-time error messages. The hints provided by these attributes are not guaranteed to be used. Unknown attributes in this namespace are accepted, though they may emit warnings for unused attributes. Additionally, invalid input to known attributes will typically be a warning (see the attribute definitions for details). This is meant to allow adding or discarding attributes and changing inputs in the future to allow changes without the need to keep the non-meaningful attributes or options working. |
Also, can you break lines after periods? That makes it easier to view diffs and refer to specific sentences.
src/attributes/diagnostics.md
Outdated
``` | ||
|
||
which then generates the for the following code | ||
|
||
```rust |
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.
I think it would be good to keep this as a single rust block so that the example can stand alone and actually generate the warning (for example, if someone presses the play button).
src/attributes/diagnostics.md
Outdated
|
||
### The `diagnostic::on_unimplemented` attribute | ||
|
||
The `#[diagnostic::on_unimplemented]` attribute is allowed to appear on trait definitions. This allows crate authors to hint the compiler to emit a specific worded error message if a certain trait is not implemented. The hinted message is supposed to replace the otherwise emitted error message. For the `#[diagnostic::on_unimplemented]` attribute the following options are implemented: |
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 allowed to appear on trait definitions.
This part doesn't seem quite correct, since it appears to be allowed to appear anywhere an attribute is allowed.
Some suggestions to try to be direct about the meaning of the attribute, exactly when it would trigger, and the allowed input for the attribute:
The `#[diagnostic::on_unimplemented]` attribute is allowed to appear on trait definitions. This allows crate authors to hint the compiler to emit a specific worded error message if a certain trait is not implemented. The hinted message is supposed to replace the otherwise emitted error message. For the `#[diagnostic::on_unimplemented]` attribute the following options are implemented: | |
The `#[diagnostic::on_unimplemented]` attribute is allowed to appear on trait definitions. This attribute hints to the compiler to supplement the error message that would normally be generated in scenarios where the trait is required but not implemented on a type. The attribute uses the [_MetaListNameValueStr_] syntax to specify its inputs, though any malformed input to the attribute is not considered as an error to provide both forwards and backwards compatibility. The following keys have the given meaning: |
This can/should get merged now |
`#[diagnostic::on_unimplemented]` feature to the reference
Co-authored-by: Eric Huss <[email protected]>
Co-authored-by: Eric Huss <[email protected]>
582a905
to
5e29b01
Compare
src/attributes/diagnostics.md
Outdated
All three options accept a string as an argument. | ||
The text in the string may contain the following format parameters which provide substitutions in the generated 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.
If this is the actual intention here, then I think an edit like the following would make sense:
All three options accept a string as an argument. | |
The text in the string may contain the following format parameters which provide substitutions in the generated message: | |
All three options accept a string as an argument, interpreted using the same formatting as a [`std::fmt`] string. | |
Format parameters with the given named parameter will be replaced with the following text: |
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.
That sound reasonable for me and that mirrors the actual implementation after the fix implemented in rust-lang/rust#122402
|
||
* `{Self}` — The name of the type implementing the trait. | ||
* `{` *GenericParameterName* `}` — The name of the generic argument's type for the given generic parameter. | ||
|
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.
Invalid format strings may generate a warning, but are otherwise allowed, but may not display as intended. | |
Format specifiers may generate a warning, but are otherwise ignored. | |
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.
That sound reasonable for me and that mirrors the actual implementation after the fix implemented in rust-lang/rust#122402
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!
Update books ## rust-lang/book 23 commits in 19c40bfd2d57641d962f3119a1c343355f1b3c5e..3131aa4642c627a24f523c82566b94a7d920f68c 2024-04-05 22:09:59 UTC to 2024-03-27 18:14:05 UTC - Correct the description of Listing 5-6 (rust-lang/book#3878) - Minor text improvements (rust-lang/book#3790) - Update full code reference main.rs in ch20-03 (rust-lang/book#3857) - Make Note text in ch. 20 consistent with other notes (rust-lang/book#3876) - Consistency fix: start note sentence with a capital (rust-lang/book#3652) - Update README.md (rust-lang/book#3656) - Update panic! formatting style for Guess example (rust-lang/book#3767) - Small correction in ch13-01 (rust-lang/book#3780) - Fix a wording typo in ch07 (rust-lang/book#3694) - Fix a typo: remove an extra 's' from ch. 18.01 (rust-lang/book#3874) - Remove redundant words (rust-lang/book#3672) - Fix rust-lang#3703 (rust-lang/book#3704) - Update loop to Result: 10 (rust-lang/book#3711) - Added "--" between run and args on ch12-03-l12 (rust-lang/book#3726) - Add maintenance time section in appendix-07-nightly-rust.md (rust-lang/book#3859) - Update the link to the farsi translation repository (rust-lang/book#3839) - Update README to use --locked for installing mdbook (rust-lang/book#3830) - Reword "`union`s" to "a `union`" (rust-lang/book#3738) - Fix two typos in 04-03 and 07-03 (rust-lang/book#3849) - Fix typo in Chapter 7 Section 3 (rust-lang/book#3743) - Improve ch03-05-control-flow collection looping wording (rust-lang/book#3758) - Fix missing column separator (rust-lang/book#3855) - Update compiler message (rust-lang/book#3856) ## rust-lang/edition-guide 3 commits in 98b33e9a441457b0a491fe1be90e7de64eafc3e5..eb3eb80e106d03250c1fb7c5666b1c8c59672862 2024-03-27 20:44:27 UTC to 2024-03-26 19:26:15 UTC - some mdbook conveniences (rust-lang/edition-guide#297) - typo (rust-lang/edition-guide#296) - Clean up the `editions/index.md` page (rust-lang/edition-guide#294) ## rust-embedded/book 1 commits in 2e95fc2fd31d669947e993aa07ef10dc9828bee7..aa7d4b0b4653ddb47cb1de2036d090ec2ba9dab1 2024-04-05 07:42:54 UTC to 2024-04-05 07:42:54 UTC - Dependencies: changed "qemu-arch-extra" to "qemu-system-arm" on arch section (rust-embedded/book#368) ## rust-lang/nomicon 2 commits in 6bc2415218d4dd0cb01433d8320f5ccf79c343a1..0d5f88475fe285affa6dbbc806e9e44d730797c0 2024-04-06 13:51:11 UTC to 2024-04-03 02:23:07 UTC - chore: fix typo (rust-lang/nomicon#448) - add link to reference about undefined behavior (rust-lang/nomicon#447) ## rust-lang/reference 3 commits in 984b36eca4b9293df04d5ba4eb5c4f77db0f51dc..55694913b1301cc809f9bf4a1ad1b3d6920efbd9 2024-04-03 21:31:14 UTC to 2024-04-01 19:56:13 UTC - Add the `#[diagnostic]` attribute namespace and the `#[diagnostic::on_unimplemented]` feature to the reference (rust-lang/reference#1449) - type-layout: be more specific about 32-bit alignments (rust-lang/reference#1393) - Fix clippy warning in procedural macro example (rust-lang/reference#1488) ## rust-lang/rust-by-example 1 commits in 7601e0c5ad29d5bd3b518700ea63fddfff5915a7..60d34b5fd33db1346f9aabfc0c9d0bda6c8e42be 2024-04-07 13:00:53 UTC to 2024-04-07 13:00:53 UTC - chore: fix some typos (rust-lang/rust-by-example#1833) ## rust-lang/rustc-dev-guide 11 commits in ffa246b..b77a34b 2024-04-06 20:41:09 UTC to 2024-03-27 08:49:05 UTC - Explicitly mention compiletest directives are supported in rmake.rs (rust-lang/rustc-dev-guide#1949) - Add docs for sharded descriptions (rust-lang/rustc-dev-guide#1959) - Add basic docs for the new `aux-bin` header (rust-lang/rustc-dev-guide#1942) - Add needs-threads header command (rust-lang/rustc-dev-guide#1943) - Fix some broken links under bootstrapping. (rust-lang/rustc-dev-guide#1958) - Replace -Zno-parallel-llvm with -Zno-parallel-backend (rust-lang/rustc-dev-guide#1957) - Rewrite the `Parameter Environments` chapter (rust-lang/rustc-dev-guide#1953) - Add quickstart for how to build and run the compiler (rust-lang/rustc-dev-guide#1951) - Delete length check (rust-lang/rustc-dev-guide#1952) - Fix some comments (rust-lang/rustc-dev-guide#1950) - add opaque-types-region-inference-restrictions (rust-lang/rustc-dev-guide#1948)
Rollup merge of rust-lang#123636 - rustbot:docs-update, r=ehuss Update books ## rust-lang/book 23 commits in 19c40bfd2d57641d962f3119a1c343355f1b3c5e..3131aa4642c627a24f523c82566b94a7d920f68c 2024-04-05 22:09:59 UTC to 2024-03-27 18:14:05 UTC - Correct the description of Listing 5-6 (rust-lang/book#3878) - Minor text improvements (rust-lang/book#3790) - Update full code reference main.rs in ch20-03 (rust-lang/book#3857) - Make Note text in ch. 20 consistent with other notes (rust-lang/book#3876) - Consistency fix: start note sentence with a capital (rust-lang/book#3652) - Update README.md (rust-lang/book#3656) - Update panic! formatting style for Guess example (rust-lang/book#3767) - Small correction in ch13-01 (rust-lang/book#3780) - Fix a wording typo in ch07 (rust-lang/book#3694) - Fix a typo: remove an extra 's' from ch. 18.01 (rust-lang/book#3874) - Remove redundant words (rust-lang/book#3672) - Fix rust-lang#3703 (rust-lang/book#3704) - Update loop to Result: 10 (rust-lang/book#3711) - Added "--" between run and args on ch12-03-l12 (rust-lang/book#3726) - Add maintenance time section in appendix-07-nightly-rust.md (rust-lang/book#3859) - Update the link to the farsi translation repository (rust-lang/book#3839) - Update README to use --locked for installing mdbook (rust-lang/book#3830) - Reword "`union`s" to "a `union`" (rust-lang/book#3738) - Fix two typos in 04-03 and 07-03 (rust-lang/book#3849) - Fix typo in Chapter 7 Section 3 (rust-lang/book#3743) - Improve ch03-05-control-flow collection looping wording (rust-lang/book#3758) - Fix missing column separator (rust-lang/book#3855) - Update compiler message (rust-lang/book#3856) ## rust-lang/edition-guide 3 commits in 98b33e9a441457b0a491fe1be90e7de64eafc3e5..eb3eb80e106d03250c1fb7c5666b1c8c59672862 2024-03-27 20:44:27 UTC to 2024-03-26 19:26:15 UTC - some mdbook conveniences (rust-lang/edition-guide#297) - typo (rust-lang/edition-guide#296) - Clean up the `editions/index.md` page (rust-lang/edition-guide#294) ## rust-embedded/book 1 commits in 2e95fc2fd31d669947e993aa07ef10dc9828bee7..aa7d4b0b4653ddb47cb1de2036d090ec2ba9dab1 2024-04-05 07:42:54 UTC to 2024-04-05 07:42:54 UTC - Dependencies: changed "qemu-arch-extra" to "qemu-system-arm" on arch section (rust-embedded/book#368) ## rust-lang/nomicon 2 commits in 6bc2415218d4dd0cb01433d8320f5ccf79c343a1..0d5f88475fe285affa6dbbc806e9e44d730797c0 2024-04-06 13:51:11 UTC to 2024-04-03 02:23:07 UTC - chore: fix typo (rust-lang/nomicon#448) - add link to reference about undefined behavior (rust-lang/nomicon#447) ## rust-lang/reference 3 commits in 984b36eca4b9293df04d5ba4eb5c4f77db0f51dc..55694913b1301cc809f9bf4a1ad1b3d6920efbd9 2024-04-03 21:31:14 UTC to 2024-04-01 19:56:13 UTC - Add the `#[diagnostic]` attribute namespace and the `#[diagnostic::on_unimplemented]` feature to the reference (rust-lang/reference#1449) - type-layout: be more specific about 32-bit alignments (rust-lang/reference#1393) - Fix clippy warning in procedural macro example (rust-lang/reference#1488) ## rust-lang/rust-by-example 1 commits in 7601e0c5ad29d5bd3b518700ea63fddfff5915a7..60d34b5fd33db1346f9aabfc0c9d0bda6c8e42be 2024-04-07 13:00:53 UTC to 2024-04-07 13:00:53 UTC - chore: fix some typos (rust-lang/rust-by-example#1833) ## rust-lang/rustc-dev-guide 11 commits in ffa246b..b77a34b 2024-04-06 20:41:09 UTC to 2024-03-27 08:49:05 UTC - Explicitly mention compiletest directives are supported in rmake.rs (rust-lang/rustc-dev-guide#1949) - Add docs for sharded descriptions (rust-lang/rustc-dev-guide#1959) - Add basic docs for the new `aux-bin` header (rust-lang/rustc-dev-guide#1942) - Add needs-threads header command (rust-lang/rustc-dev-guide#1943) - Fix some broken links under bootstrapping. (rust-lang/rustc-dev-guide#1958) - Replace -Zno-parallel-llvm with -Zno-parallel-backend (rust-lang/rustc-dev-guide#1957) - Rewrite the `Parameter Environments` chapter (rust-lang/rustc-dev-guide#1953) - Add quickstart for how to build and run the compiler (rust-lang/rustc-dev-guide#1951) - Delete length check (rust-lang/rustc-dev-guide#1952) - Fix some comments (rust-lang/rustc-dev-guide#1950) - add opaque-types-region-inference-restrictions (rust-lang/rustc-dev-guide#1948)
As requested here