rust/library/core/src
Georg Semmler dd31713c53
Stabilize #[diagnostic::do_not_recommend]
This commit seeks to stabilize the `#[diagnostic::do_not_recommend]`
attribute.
This attribute was first proposed as `#[do_not_recommend`] attribute in
RFC 2397 (https://github.com/rust-lang/rfcs/pull/2397). It gives the
crate authors the ability to not suggest to the compiler to not show
certain traits in it's error messages. With the presence of the
`#[diagnostic]` tool attribute namespace it was decided to move the
attribute there, as that lowers the amount of guarantees the compiler
needs to give about the exact way this influences error messages. It
turns the attribute into a hint which can be ignored. In addition to the
original proposed functionality this attribute now also hides the marked
trait in help messages ("This trait is implemented by: ").
The attribute does not accept any argument and can only be placed on
trait implementations. If it is placed somewhere else a lint warning is
emitted and the attribute is otherwise ignored. If an argument is
detected a lint warning is emitted and the argument is ignored. This
follows the rules outlined by the diagnostic namespace.

This attribute allows crates like diesel to improve their error messages
drastically. The most common example here is the following error
message:

```
error[E0277]: the trait bound `&str: Expression` is not satisfied
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>`
   |
   = help: the following other types implement trait `Expression`:
             Bound<T>
             SelectInt
note: required for `&str` to implement `AsExpression<Integer>`
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13
   |
LL | impl<T, ST> AsExpression<ST> for T
   |             ^^^^^^^^^^^^^^^^     ^
LL | where
LL |     T: Expression<SqlType = ST>,
   |        ------------------------ unsatisfied trait bound introduced here
```

By applying the new attribute to the wild card trait implementation of
`AsExpression` for `T: Expression` the error message becomes:

```
error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied
  --> $DIR/as_expression.rs:55:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `AsExpression<Integer>` is not implemented for `&str`
   |
   = help: the trait `AsExpression<Text>` is implemented for `&str`
   = help: for that trait implementation, expected `Text`, found `Integer`
```

which makes it much easier for users to understand that they are facing
a type mismatch.

Other explored example usages included

* This standard library error message: https://github.com/rust-lang/rust/pull/128008
* That bevy derived example:
e1f3068995/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No
more tuple pyramids)

Fixes #51992
2024-12-18 07:10:53 +01:00
..
alloc stabilize const_{size,align}_of_val 2024-12-02 20:18:25 +01:00
array Add '<[T]>::as_array', '<[T]>::as_mut_array', '<*const [T]>::as_array', and '<*mut [T]>::as_mut_array' conversion methods; 2024-11-26 21:49:28 +01:00
ascii Add more precondition check tests 2024-10-09 19:34:27 -04:00
async_iter Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
cell Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
char update cfgs 2024-11-27 15:14:54 +00:00
clone CloneToUninit: use a private specialization trait 2024-07-29 20:44:43 +03:00
cmp Use generic NonZero everywhere in core. 2024-02-22 15:17:33 +01:00
convert rustdoc-search: let From and Into be unboxed 2024-12-13 11:05:30 -07:00
ffi Add references to the specific ABI documents 2024-12-10 08:33:29 -08:00
fmt Switch inline(always) in core/src/fmt/rt.rs to plain inline 2024-12-08 15:41:00 -05:00
future update cfgs 2024-11-27 15:14:54 +00:00
hash stabilize const_collections_with_hasher and build_hasher_default_const_new 2024-12-02 16:34:39 +01:00
intrinsics Adds new intrinsic declaration 2024-12-08 19:46:45 +05:30
io Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime 2024-11-02 14:26:21 -04:00
iter Correct spelling of CURRENT_RUSTC_VERSION 2024-12-14 21:40:11 +01:00
macros Stabilize #[coverage] attribute 2024-12-16 21:07:06 -05:00
mem Rollup merge of #133762 - RalfJung:const-size-of-val, r=workingjubilee 2024-12-03 17:27:09 +01:00
net replace placeholder version 2024-11-27 12:10:21 +00:00
num Fix typo in uint_macros.rs 2024-12-17 14:43:22 +01:00
ops Stabilize async closures 2024-12-13 00:04:56 +00:00
panic replace placeholder version 2024-11-27 12:10:21 +00:00
prelude Stabilize the Rust 2024 prelude 2024-12-11 13:09:57 -08:00
ptr Fix typos in docs on provenance 2024-12-12 22:52:12 +03:00
range Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
slice Replace i32 by char in split_at & _unchecked 2024-12-14 14:25:55 +00:00
str update cfgs 2024-11-27 15:14:54 +00:00
sync replace placeholder version 2024-11-27 12:10:21 +00:00
task Remove rustc_const_stable attribute on const NOOP 2024-12-09 15:08:30 -08:00
unicode Reformat Python code with ruff 2024-12-04 23:03:44 +01:00
any.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
arch.rs Add core::arch::breakpoint and test 2024-12-02 23:56:24 -08:00
ascii.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
asserting.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
bool.rs Add doc alias 'then_with' for then method on bool 2024-12-03 09:20:34 +02:00
borrow.rs Suggest borrowing on fn argument that is impl AsRef 2024-05-09 23:25:31 +00:00
cell.rs get rid of a bunch of unnecessary rustc_const_unstable 2024-11-30 11:55:58 +01:00
clone.rs Make CloneToUninit dyn-compatible 2024-11-12 15:08:41 -06:00
cmp.rs Stabilize #[coverage] attribute 2024-12-16 21:07:06 -05:00
default.rs update cfgs 2024-09-05 17:24:01 +01:00
error.md Mention core's PanicInfo in error.md. 2024-06-11 15:47:00 +02:00
error.rs Update includes in '/library/core/src/error.rs'; 2024-12-13 12:46:20 +01:00
escape.rs Optimize escape_ascii 2024-10-09 17:17:50 -04:00
hint.rs feat: clarify how to use black_box() 2024-12-12 13:54:17 -05:00
internal_macros.rs Fix doc nits 2024-07-26 13:26:33 +01:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs Stabilize #[diagnostic::do_not_recommend] 2024-12-18 07:10:53 +01:00
marker.rs Constify Drop and Destruct 2024-11-25 17:27:41 +00:00
option.rs update cfgs 2024-11-27 15:14:54 +00:00
panic.rs update cfgs 2024-11-27 15:14:54 +00:00
panicking.rs update cfgs 2024-11-27 15:14:54 +00:00
pat.rs Rename core_pattern_type and core_pattern_types lib feature gates to pattern_type_macro 2024-12-04 16:16:24 +00:00
pin.rs Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrum 2024-11-29 22:39:10 +00:00
primitive.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
primitive_docs.rs Rollup merge of #132136 - RalfJung:target-feature-abi-compat, r=Mark-Simulacrum 2024-11-10 10:09:52 +01:00
random.rs random: add tracking issue, address other comments 2024-09-23 10:36:16 +02:00
range.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
result.rs update cfgs 2024-11-27 15:14:54 +00:00
time.rs get rid of a whole bunch of unnecessary rustc_const_unstable attributes 2024-11-02 09:59:55 +01:00
tuple.rs update cfgs 2024-09-05 17:24:01 +01:00
ub_checks.rs update cfgs 2024-11-27 15:14:54 +00:00
unit.rs Import the 2021 prelude in the core crate 2024-03-25 13:12:06 -07:00
unsafe_binder.rs Add unwrap_unsafe_binder and wrap_unsafe_binder macro operators 2024-12-12 16:29:40 +00:00