rust/compiler
Jacob Pratt e018796012
Rollup merge of #132056 - weiznich:diagnostic_do_not_recommend_final_tests, r=compiler-errors
Stabilize `#[diagnostic::do_not_recommend]`

This PR 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 its 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 include:

* 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

r? ``@compiler-errors``

This PR also adds a few more tests, makes sure that all the tests are run for the old and new trait solver and adds a check that the attribute does not contain arguments.
2024-12-18 21:38:08 -05:00
..
rustc switch jemalloc-sys back to tikv-jemalloc-sys, and update to 0.6.0 2024-12-03 08:56:33 +00:00
rustc_abi Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_arena move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_ast Rollup merge of #134253 - nnethercote:overhaul-keywords, r=petrochenkov 2024-12-18 22:56:53 +08:00
rustc_ast_ir
rustc_ast_lowering Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_ast_passes Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_ast_pretty Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino 2024-12-18 22:56:53 +08:00
rustc_attr_data_structures rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structures 2024-12-16 19:08:19 +01:00
rustc_attr_parsing Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_baked_icu_data Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_borrowck Auto merge of #133328 - nnethercote:simplify-SwitchInt-handling, r=tmiasko 2024-12-18 22:57:23 +00:00
rustc_builtin_macros Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino 2024-12-18 22:56:53 +08:00
rustc_codegen_cranelift Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_codegen_gcc rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structures 2024-12-16 19:08:19 +01:00
rustc_codegen_llvm Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
rustc_codegen_ssa Auto merge of #134425 - clubby789:cargo-update, r=jieyouxu 2024-12-18 09:23:22 +00:00
rustc_const_eval Auto merge of #134443 - joshtriplett:use-field-init-shorthand, r=lqd,tgross35,nnethercote 2024-12-18 19:16:15 +00:00
rustc_data_structures Remove jobserver from Session 2024-12-13 10:21:22 +00:00
rustc_driver
rustc_driver_impl Rollup merge of #134420 - Integral-Tech:pathbuf-refactor, r=compiler-errors 2024-12-18 22:56:56 +08:00
rustc_error_codes Auto merge of #132706 - compiler-errors:async-closures, r=oli-obk 2024-12-13 00:37:51 +00:00
rustc_error_messages Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_errors Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
rustc_expand Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino 2024-12-18 22:56:53 +08:00
rustc_feature Stabilize #[diagnostic::do_not_recommend] 2024-12-18 07:10:53 +01:00
rustc_fluent_macro use tracked_path in rustc_fluent_macro 2024-10-19 22:32:38 +08:00
rustc_fs_util
rustc_graphviz
rustc_hir Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_hir_analysis Rollup merge of #133926 - compiler-errors:const-conditions, r=lcnr 2024-12-18 22:56:52 +08:00
rustc_hir_pretty Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_hir_typeck Rollup merge of #134394 - dianne:clarify-pat-2024-migration, r=compiler-errors 2024-12-18 22:56:54 +08:00
rustc_incremental Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_index Use BitSet in SparseBitMatrix. 2024-12-09 08:53:33 +11:00
rustc_index_macros Auto merge of #130867 - michirakara:steps_between, r=dtolnay 2024-11-22 10:54:22 +00:00
rustc_infer Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_interface Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_lexer Add test to check unicode identifier version 2024-12-09 06:23:59 -08:00
rustc_lint Auto merge of #134443 - joshtriplett:use-field-init-shorthand, r=lqd,tgross35,nnethercote 2024-12-18 19:16:15 +00:00
rustc_lint_defs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_llvm Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errors 2024-12-12 02:34:06 +00:00
rustc_log
rustc_macros Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_metadata Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
rustc_middle Rollup merge of #134394 - dianne:clarify-pat-2024-migration, r=compiler-errors 2024-12-18 22:56:54 +08:00
rustc_mir_build Rollup merge of #134399 - spastorino:invert-if-condition, r=jieyouxu 2024-12-18 22:56:55 +08:00
rustc_mir_dataflow Auto merge of #133328 - nnethercote:simplify-SwitchInt-handling, r=tmiasko 2024-12-18 22:57:23 +00:00
rustc_mir_transform mir-opt: Do not handle the cleanup BB in the EarlyOtherwiseBranch 2024-12-18 20:43:55 +08:00
rustc_monomorphize Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_next_trait_solver Rename projection_def_id to item_def_id 2024-12-11 00:59:43 +00:00
rustc_parse Auto merge of #134443 - joshtriplett:use-field-init-shorthand, r=lqd,tgross35,nnethercote 2024-12-18 19:16:15 +00:00
rustc_parse_format Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_passes Also warn against #[diagnostic::do_not_recommend] on plain impls 2024-12-18 07:10:55 +01:00
rustc_pattern_analysis no more Reveal :( 2024-11-23 13:52:54 +01:00
rustc_privacy Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_query_impl Rename ty_def_id so people will stop using it by accident 2024-12-13 16:36:38 +00:00
rustc_query_system Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_resolve Stabilize #[diagnostic::do_not_recommend] 2024-12-18 07:10:53 +01:00
rustc_sanitizers Remove more traces of anonymous ADTs 2024-12-10 19:50:47 +00:00
rustc_serialize Fix explicit_iter_loop in rustc_serialize 2024-10-16 15:44:16 +02:00
rustc_session Rollup merge of #134420 - Integral-Tech:pathbuf-refactor, r=compiler-errors 2024-12-18 22:56:56 +08:00
rustc_smir Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_span Improve comments on Keywords. 2024-12-18 20:21:03 +11:00
rustc_symbol_mangling Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_target Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
rustc_trait_selection Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
rustc_traits Delay a bug when encountering an impl with unconstrained generics in codegen_select 2024-11-23 05:27:45 +00:00
rustc_transmute Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_ty_utils Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
rustc_type_ir Use field init shorthand where possible 2024-12-17 14:33:10 -08:00
rustc_type_ir_macros do not relate Abi and Safety 2024-10-22 23:13:04 +02:00
stable_mir Encode coroutine-closures in SMIR 2024-12-14 03:45:35 +00:00