You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/attributes/diagnostics.md
+41Lines changed: 41 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -492,6 +492,47 @@ error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
492
492
= note: Note 2
493
493
```
494
494
495
+
### The `diagnostic::do_not_recommend` attribute
496
+
497
+
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to not show a certain trait implementation as part of the error message.
498
+
The attribute should be placed on a [trait implementation items]. It does not accept any arguments. If the attribute is placed in a wrong location or contains an unexpected argument the compiler might emit a warning and otherwise ignore the malformed part.
499
+
500
+
In this example:
501
+
502
+
```rust,compile_fail,E0277
503
+
trait Foo {}
504
+
505
+
#[diagnostic::do_not_recommend]
506
+
impl<T> Foo for T where T: Send {}
507
+
508
+
fn needs_foo<T: Foo>() {}
509
+
510
+
fn main() {
511
+
needs_foo::<*mut ()>();
512
+
}
513
+
514
+
```
515
+
516
+
the compiler may generate an error message which looks like this:
517
+
518
+
```text
519
+
error[E0277]: the trait bound `*mut (): Foo` is not satisfied
520
+
--> $DIR/simple.rs:15:17
521
+
|
522
+
LL | needs_foo::<*mut ()>();
523
+
| ^^^^^^^ the trait `Foo` is not implemented for `*mut ()`
524
+
|
525
+
note: required by a bound in `needs_foo`
526
+
--> $DIR/simple.rs:10:17
527
+
|
528
+
LL | fn needs_foo<T: Foo>() {}
529
+
| ^^^ required by this bound in `needs_foo`
530
+
531
+
error: aborting due to 1 previous error
532
+
```
533
+
534
+
Without the attribute the compiler would complain about `*mut (): Send` instead.
0 commit comments