diff --git a/src/attributes.md b/src/attributes.md index fd7dacac8..caaf836c1 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -268,6 +268,7 @@ The following is an index of all built-in attributes. - [`must_use`] --- Generates a lint for unused values. - [`diagnostic::on_unimplemented`] --- Hints the compiler to emit a certain error message if a trait is not implemented. + - [`diagnostic::do_not_recommend`] --- Hints the compiler to not show a certain trait impl in error messages. - ABI, linking, symbols, and FFI - [`link`] --- Specifies a native library to link with an `extern` block. @@ -414,3 +415,4 @@ The following is an index of all built-in attributes. [function pointer]: types/function-pointer.md [variadic functions]: items/external-blocks.html#variadic-functions [`diagnostic::on_unimplemented`]: attributes/diagnostics.md#the-diagnosticon_unimplemented-attribute +[`diagnostic::do_not_recommend`]: attributes/diagnostics.md#the-diagnosticdo_not_recommend-attribute diff --git a/src/attributes/diagnostics.md b/src/attributes/diagnostics.md index c75915d51..651554c5e 100644 --- a/src/attributes/diagnostics.md +++ b/src/attributes/diagnostics.md @@ -329,7 +329,7 @@ The `deprecated` attribute has several forms: r[attributes.diagnostic.deprecated.allowed-positions] The `deprecated` attribute may be applied to any [item], [trait item], [enum variant], [struct field], [external block item], or [macro definition]. It -cannot be applied to [trait implementation items]. When applied to an item +cannot be applied to [trait implementation items][trait-impl]. When applied to an item containing other items, such as a [module] or [implementation], all child items inherit the deprecation attribute. src/main.rs:53:15 + | +53 | SelectInt.check("bar"); + | ^^^^^ the trait `Expression` is not implemented for `&str` + | + = help: the following other types implement trait `Expression`: + Bound + SelectInt +note: required for `&str` to implement `AsExpression` + --> src/main.rs:45:13 + | +45 | impl AsExpression for T + | ^^^^^^^^^^^^^^^^ ^ +46 | where +47 | T: Expression, + | ------------------------ unsatisfied trait bound introduced here +``` + +By adding the `#[diagnostic::do_no_recommend]` attribute to the blanket `impl` for `AsExpression`, the message changes to: + +```text +error[E0277]: the trait bound `&str: AsExpression` is not satisfied + --> src/main.rs:53:15 + | +53 | SelectInt.check("bar"); + | ^^^^^ the trait `AsExpression` is not implemented for `&str` + | + = help: the trait `AsExpression` is not implemented for `&str` + but trait `AsExpression` is implemented for it + = help: for that trait implementation, expected `Text`, found `Integer` +``` + +The first error message includes a somewhat confusing error message about the relationship of `&str` and `Expression`, as well as the unsatisfied trait bound in the blanket impl. After adding `#[diagnostic::do_no_recommend]`, it no longer considers the blanket impl for the recommendation. The message should be a little clearer, with an indication that a string cannot be converted to an `Integer`. + [Clippy]: https://github.com/rust-lang/rust-clippy [_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax [_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax @@ -587,7 +700,7 @@ error[E0277]: My Message for `ImportantTrait` implemented for `String` [struct field]: ../items/structs.md [struct]: ../items/structs.md [trait declaration]: ../items/traits.md -[trait implementation items]: ../items/implementations.md#trait-implementations [trait item]: ../items/traits.md +[trait-impl]: ../items/implementations.md#trait-implementations [traits]: ../items/traits.md [union]: ../items/unions.md