diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-10-11 03:53:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-11 03:53:17 +0300 |
| commit | 494e97174a5126895d1dd2ee2863315120a877c7 (patch) | |
| tree | f5ed386d35cb5379ce02cbe4e5815f526973e502 | |
| parent | a7042a94a372bf272a0a217e612603e04942db50 (diff) | |
| parent | ba02a9909b7e53245abe98981420ed721610b1ef (diff) | |
| download | rust-494e97174a5126895d1dd2ee2863315120a877c7.tar.gz rust-494e97174a5126895d1dd2ee2863315120a877c7.zip | |
Rollup merge of #116611 - mejrs:diagnostic_namespace, r=ehuss
Document `diagnostic_namespace` feature This adds it to the rust unstable book. FWIW: I couldn't find a way to serve the book locally (please send help), so I can't check that this renders correctly. cc `@weiznich`
| -rw-r--r-- | src/doc/unstable-book/src/language-features/diagnostic-namespace.md | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/diagnostic-namespace.md b/src/doc/unstable-book/src/language-features/diagnostic-namespace.md new file mode 100644 index 00000000000..7c46811a27a --- /dev/null +++ b/src/doc/unstable-book/src/language-features/diagnostic-namespace.md @@ -0,0 +1,84 @@ +# `diagnostic_namespace` + +The tracking issue for this feature is: [#111996] + +[#111996]: https://github.com/rust-lang/rust/issues/111996 + +------------------------ + +The `diagnostic_namespace` feature permits customization of compilation errors. + +## diagnostic::on_unimplemented + +With [#114452] support for `diagnostic::on_unimplemented` was added. + +When used on a trait declaration, the following options are available: + +* `message` to customize the primary error message +* `note` to add a customized note message to an error message +* `label` to customize the label part of the error message + +The attribute will hint to the compiler to use these in error messages: +```rust +// some library +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented( + message = "cannot insert element", + label = "cannot be put into a table", + note = "see <link> for more information about the Table api" +)] +pub trait Element { + // ... +} +``` + +```rust,compile_fail,E0277 +# #![feature(diagnostic_namespace)] +# +# #[diagnostic::on_unimplemented( +# message = "cannot insert element", +# label = "cannot be put into a table", +# note = "see <link> for more information about the Table api" +# )] +# pub trait Element { +# // ... +# } +# struct Table; +# impl Table { +# fn insert<T: Element>(&self, element: T) { +# // .. +# } +# } +# fn main() { +# let table = Table; +# let element = (); +// user code +table.insert(element); +# } +``` + +```text +error[E0277]: cannot insert element + --> src/main.rs:24:18 + | +24 | table.insert(element); + | ------ ^^^^^^^ cannot be put into a table + | | + | required by a bound introduced by this call + | + = help: the trait `Element` is not implemented for `<type>` + = note: see <link> for more information about the Table api +note: required by a bound in `Table::insert` + --> src/main.rs:15:18 + | +15 | fn insert<T: Element>(&self, element: T) { + | ^^^^^^^ required by this bound in `Table::insert` + +For more information about this error, try `rustc --explain E0277`. +``` + +See [RFC 3368] for more information. + +[#114452]: https://github.com/rust-lang/rust/pull/114452 +[RFC 3368]: https://github.com/rust-lang/rfcs/blob/master/text/3368-diagnostic-attribute-namespace.md |
