Skip to content

Commit 582a905

Browse files
weiznichehuss
andcommitted
Apply more review suggestions manually
Co-authored-by: Eric Huss <[email protected]>
1 parent ed6d243 commit 582a905

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/attributes/diagnostics.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,29 @@ When used on a function in a trait implementation, the attribute does nothing.
303303
304304
## The `diagnostic` tool attribute namespace
305305
306-
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.
306+
The `#[diagnostic]` attribute namespace is meant to provide a home for attributes to influence compile-time error messages.
307+
The hints provides by these attributes are not guaranteed to be used.
308+
Unknown attributes in this namespace are accepted, though tey may emit warings for unused attributes.
309+
Additionally, invalid input to known attributes will typically be a warning (see the attribute definitions for details).
310+
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.
307311
308312
### The `diagnostic::on_unimplemented` attribute
309313
310-
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:
314+
The `#[diagnostic::on_unimplemented]` attribute is designed to appear on trait definitions.
315+
This attribute hints to hint the compiler to supplement a specific worded error message that would normally be generated in scenarios where the trait is required but not implemented on a type
316+
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:
311317
312318
* `message` which provides the text for the top level error message
313319
* `label` which provides the text for the label shown inline in the broken code in the error message
314320
* `note` which provides additional notes.
315321
316-
The `note` option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated.
322+
The `note` option can appear several times, which results in several note messages being emitted.
323+
If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning.
324+
For any other non-existing option a lint-warning is generated.
317325
318-
All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or `Self` by name via the `{Self}` or `{NameOfGenericArgument}` syntax. Any other format parameter will generate a warning, but will otherwise be included in the string as-is.
326+
All three options accept a text as argument.
327+
This text is allowed to contain format parameters referring to generic argument or `Self` by name via the `{Self}` or `{NameOfGenericArgument}` syntax, where `{Self}` is resolved to the name of the type implementing the trait and `{NameOfGenericArgument}` is resolved to the relevant type name that replaces the `{NameOfGenericArgument}` argument if the error message is emitted.
328+
Any other format parameter will generate a warning, but will otherwise be included in the string as-is.
319329
320330
This allows to have a trait definition like:
321331
@@ -327,19 +337,15 @@ This allows to have a trait definition like:
327337
note = "Note 2"
328338
)]
329339
trait ImportantTrait<A> {}
330-
```
331-
332-
which then generates the for the following code
333340
334-
```rust
335341
fn use_my_trait(_: impl ImportantTrait<i32>) {}
336342
337343
fn main() {
338344
use_my_trait(String::new());
339345
}
340346
```
341347
342-
this error message:
348+
which might generate this error message:
343349

344350
```
345351
error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`

0 commit comments

Comments
 (0)