@@ -479,6 +479,42 @@ r[attributes.diagnostic.on_unimplemented]
479479r [attributes . diagnostic. on_unimplemented. intro]
480480The `#[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 .
481481
482+ > [! EXAMPLE ]
483+ > In this example :
484+ >
485+ > ```rust ,compile_fail ,E0277
486+ > #[diagnostic:: on_unimplemented(
487+ > message = " My Message for `ImportantTrait<{A}>` implemented for `{Self}`" ,
488+ > label = " My Label" ,
489+ > note = " Note 1" ,
490+ > note = " Note 2"
491+ > )]
492+ > trait ImportantTrait <A > {}
493+ >
494+ > fn use_my_trait (_ : impl ImportantTrait <i32 >) {}
495+ >
496+ > fn main () {
497+ > use_my_trait (String :: new ());
498+ > }
499+ > ```
500+ >
501+ > the compiler may generate an error message which looks like this :
502+ >
503+ > ```text
504+ > error [E0277 ]: My Message for `ImportantTrait <i32 >` implemented for `String `
505+ > - -> src / main . rs: 14 : 18
506+ > |
507+ > 14 | use_my_trait (String :: new ());
508+ > | ------------ ^^^^^^^^^^^^^ My Label
509+ > | |
510+ > | required by a bound introduced by this call
511+ > |
512+ > = help : the trait `ImportantTrait <i32 >` is not implemented for `String `
513+ > = note : Note 1
514+ > = note : Note 2
515+ > ```
516+
517+
482518r [attributes . diagnostic. on_unimplemented. allowed- positions ]
483519The attribute should be placed on a [trait declaration ], though it is not an error to be located in other positions .
484520
@@ -515,40 +551,6 @@ r[attributes.diagnostic.on_unimplemented.invalid-string]
515551Invalid format strings may generate a warning , but are otherwise allowed , but may not display as intended .
516552Format specifiers may generate a warning , but are otherwise ignored .
517553
518- In this example :
519-
520- ```rust ,compile_fail ,E0277
521- #[diagnostic:: on_unimplemented(
522- message = " My Message for `ImportantTrait<{A}>` implemented for `{Self}`" ,
523- label = " My Label" ,
524- note = " Note 1" ,
525- note = " Note 2"
526- )]
527- trait ImportantTrait <A > {}
528-
529- fn use_my_trait (_ : impl ImportantTrait <i32 >) {}
530-
531- fn main () {
532- use_my_trait (String :: new ());
533- }
534- ```
535-
536- the compiler may generate an error message which looks like this:
537-
538- ``` text
539- error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
540- --> src/main.rs:14:18
541- |
542- 14 | use_my_trait(String::new());
543- | ------------ ^^^^^^^^^^^^^ My Label
544- | |
545- | required by a bound introduced by this call
546- |
547- = help: the trait `ImportantTrait<i32>` is not implemented for `String`
548- = note: Note 1
549- = note: Note 2
550- ```
551-
552554r [attributes . diagnostic. do_not_recommend]
553555### The `diagnostic :: do_not_recommend ` attribute
554556
0 commit comments