@@ -303,33 +303,39 @@ When used on a function in a trait implementation, the attribute does nothing.
303
303
304
304
## The `diagnostic ` tool attribute namespace
305
305
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 ).
306
+ The `#[diagnostic]` attribute namespace is a home for attributes to influence compile - time error messages .
307
+ The hints provided by these attributes are not guaranteed to be used .
308
+ Unknown attributes in this namespace are accepted , though they may emit warnings for unused attributes .
309
+ Additionally , invalid inputs to known attributes will typically be a warning (see the attribute definitions for details ).
310
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 .
311
311
312
312
### The `diagnostic :: on_unimplemented ` attribute
313
313
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 :
314
+ The `#[diagnostic:: on_unimplemented]` attribute is a hint to the compiler to supplement the error message that would normally be generated in scenarios where a trait is required but not implemented on a type .
315
+ The attribute should be placed on a [trait declaration ], though it is not an error to be located in other positions .
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 .
317
+ The following keys have the given meaning :
317
318
318
- * `message ` which provides the text for the top level error message
319
- * `label ` which provides the text for the label shown inline in the broken code in the error message
320
- * `note ` which provides additional notes .
319
+ * `message ` — The text for the top level error message .
320
+ * `label ` — The text for the label shown inline in the broken code in the error message .
321
+ * `note ` — Provides additional notes .
321
322
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 .
323
+ The `note ` option can appear several times , which results in several note messages being emitted .
324
+ If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value .
325
+ Any other occurrence generates an lint warning .
324
326
For any other non - existing option a lint - warning is generated .
325
327
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
+ All three options accept a string as an argument .
329
+ The text in the string may contain the following format parameters which provide substitutions in the generated message :
330
+
331
+ * `{Self }` — The name of the type implementing the trait .
332
+ * `{` * GenericParameterName * `}` — The name of the generic argument 's type for the given generic parameter .
333
+
328
334
Any other format parameter will generate a warning , but will otherwise be included in the string as - is .
329
335
330
- This allows to have a trait definition like :
336
+ In this example :
331
337
332
- ```rust
338
+ ```rust , compile_fail , E0277
333
339
#[diagnostic:: on_unimplemented(
334
340
message = " My Message for `ImportantTrait<{A}>` implemented for `{Self}`" ,
335
341
label = " My Label" ,
@@ -345,9 +351,9 @@ fn main() {
345
351
}
346
352
```
347
353
348
- which might generate this error message:
354
+ the compiler may generate an error message which looks like this :
349
355
350
- ```
356
+ ``` text
351
357
error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
352
358
--> src/main.rs:14:18
353
359
|
0 commit comments