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
This adds some more explanation about the use of
`diagnostic::do_not_recommend`, with the intent of helping the reader to
understand how to use it. This also breaks that discussion out into a
note.
This also adds a before/after to the example to better show how it
changes.
Copy file name to clipboardExpand all lines: src/attributes/diagnostics.md
+32-12
Original file line number
Diff line number
Diff line change
@@ -564,50 +564,70 @@ error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
564
564
r[attributes.diagnostic.do_not_recommend]
565
565
566
566
r[attributes.diagnostic.do_not_recommend.intro]
567
-
The `#[diagnostic::do_not_recommend]` attribute is a hint to the compiler to not show the annotated trait implementation as part of a diagnostic message. For example, in an error message about a type not implementing a required trait, the compiler may indicate that an unsatisfied trait bound is a result of the given trait implementation. The `#[diagnostic::do_not_recommend]` attribute can be used to prevent those annotations about the trait implementation from being included in the diagnostic when they are unlikely to be useful.
567
+
The `#[diagnostic::do_not_recommend]` attribute is a hint to the compiler to not show the annotated trait implementation as part of a diagnostic message.
568
+
569
+
> **Note**: Suppressing the recommendation can be useful if you know that the recommendation would not be useful to the programmer. This often occurs with broad, blanket impls. The recommendation may send the programmer down the wrong path, or the trait implementation may be an internal detail that you don't want to expose, or the bounds may not be able to be satisfied by the programmer.
570
+
>
571
+
> For example, in an error message about a type not implementing a required trait, the compiler may find a trait implementation that would satisfy the requirements if it weren't for specific bounds in the trait implementation. The compiler may tell the user that there is an impl, but the problem is the bounds in the trait implementation. The `#[diagnostic::do_not_recommend]` attribute can be used to tell the compiler to *not* tell the user about the trait implementation, and instead simply tell the user the type doesn't implement the required trait.
0 commit comments