| 
 | 1 | +# `diagnostic_namespace`  | 
 | 2 | + | 
 | 3 | +The tracking issue for this feature is: [#111996]  | 
 | 4 | + | 
 | 5 | +[#111996]: https://github.com/rust-lang/rust/issues/111996  | 
 | 6 | + | 
 | 7 | +------------------------  | 
 | 8 | + | 
 | 9 | +The `diagnostic_namespace` feature permits customization of compilation errors.  | 
 | 10 | + | 
 | 11 | +## diagnostic::on_unimplemented  | 
 | 12 | + | 
 | 13 | +With [#114452] support for `diagnostic::on_unimplemented` was added.  | 
 | 14 | + | 
 | 15 | +When used on a trait declaration, the following options are available:  | 
 | 16 | + | 
 | 17 | +* `message` to customize the primary error message  | 
 | 18 | +* `note` to add a customized note message to an error message  | 
 | 19 | +* `label` to customize the label part of the error message  | 
 | 20 | + | 
 | 21 | +The attribute will hint to the compiler to use these in error messages:  | 
 | 22 | +```rust  | 
 | 23 | +// some library  | 
 | 24 | +#![feature(diagnostic_namespace)]  | 
 | 25 | + | 
 | 26 | +#[diagnostic::on_unimplemented(  | 
 | 27 | +    message = "cannot insert element",  | 
 | 28 | +    label = "cannot be put into a table",  | 
 | 29 | +    note = "see <link> for more information about the Table api"  | 
 | 30 | +)]  | 
 | 31 | +pub trait Element {  | 
 | 32 | +    // ...  | 
 | 33 | +}  | 
 | 34 | +```  | 
 | 35 | + | 
 | 36 | +```rust,compile_fail,E0277  | 
 | 37 | +# #![feature(diagnostic_namespace)]  | 
 | 38 | +#  | 
 | 39 | +# #[diagnostic::on_unimplemented(  | 
 | 40 | +#    message = "cannot insert element",  | 
 | 41 | +#    label = "cannot be put into a table",  | 
 | 42 | +#    note = "see <link> for more information about the Table api"  | 
 | 43 | +# )]  | 
 | 44 | +# pub trait Element {  | 
 | 45 | +#    // ...  | 
 | 46 | +# }  | 
 | 47 | +# struct Table;  | 
 | 48 | +# impl Table {  | 
 | 49 | +#    fn insert<T: Element>(&self, element: T) {  | 
 | 50 | +#        // ..  | 
 | 51 | +#    }  | 
 | 52 | +# }  | 
 | 53 | +# fn main() {  | 
 | 54 | +#    let table = Table;  | 
 | 55 | +#    let element = ();  | 
 | 56 | +// user code  | 
 | 57 | +table.insert(element);  | 
 | 58 | +# }  | 
 | 59 | +```  | 
 | 60 | + | 
 | 61 | +```text  | 
 | 62 | +error[E0277]: cannot insert element  | 
 | 63 | +  --> src/main.rs:24:18  | 
 | 64 | +   |  | 
 | 65 | +24 |     table.insert(element);  | 
 | 66 | +   |           ------ ^^^^^^^ cannot be put into a table  | 
 | 67 | +   |           |  | 
 | 68 | +   |           required by a bound introduced by this call  | 
 | 69 | +   |  | 
 | 70 | +   = help: the trait `Element` is not implemented for `<type>`  | 
 | 71 | +   = note: see <link> for more information about the Table api  | 
 | 72 | +note: required by a bound in `Table::insert`  | 
 | 73 | +  --> src/main.rs:15:18  | 
 | 74 | +   |  | 
 | 75 | +15 |     fn insert<T: Element>(&self, element: T) {  | 
 | 76 | +   |                  ^^^^^^^ required by this bound in `Table::insert`  | 
 | 77 | +
  | 
 | 78 | +For more information about this error, try `rustc --explain E0277`.  | 
 | 79 | +```  | 
 | 80 | + | 
 | 81 | +See [RFC 3368] for more information.  | 
 | 82 | + | 
 | 83 | +[#114452]: https://github.com/rust-lang/rust/pull/114452  | 
 | 84 | +[RFC 3368]: https://github.com/rust-lang/rfcs/blob/master/text/3368-diagnostic-attribute-namespace.md  | 
0 commit comments