Skip to content

Commit dd9e6cc

Browse files
committed
Add a real example of #[diagnostic::on_unimplemented]
1 parent 08053c4 commit dd9e6cc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

posts/2024-05-02-Rust-1.78.0.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ error[E0277]: My Message for `ImportantTrait<i32>` is not implemented for `Strin
7070
= note: Note 2
7171
```
7272

73+
For trait authors, this kind of diagnostic is more useful if you can provide a better hint than just talking about the missing implementation itself. For example, this is an abridged sample from the standard library:
74+
75+
```rust
76+
#[diagnostic::on_unimplemented(
77+
message = "the size for values of type `{Self}` cannot be known at compilation time",
78+
label = "doesn't have a size known at compile-time"
79+
)]
80+
pub trait Sized {}
81+
```
82+
7383
For more information, see the reference section on [the `diagnostic` tool attribute namespace](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace).
7484

7585
### Asserting `unsafe` preconditions

0 commit comments

Comments
 (0)