forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#132056 - weiznich:diagnostic_do_not_recomme…
…nd_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 (rust-lang/rfcs#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: rust-lang#128008 * That bevy derived example: https://github.com/rust-lang/rust/blob/e1f306899514ea80abc1d1c9f6a57762afb304a3/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No more tuple pyramids) Fixes rust-lang#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.
- Loading branch information
Showing
41 changed files
with
300 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/ui/diagnostic_namespace/do_not_recommend/as_expression.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...s/ui/diagnostic_namespace/do_not_recommend/do_not_apply_attribute_without_feature_flag.rs
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
.../diagnostic_namespace/do_not_recommend/do_not_apply_attribute_without_feature_flag.stderr
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
tests/ui/diagnostic_namespace/do_not_recommend/does_not_acccept_args.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:10:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default | ||
|
||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:14:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted = "foo")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:18:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted(42))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 3 warnings emitted | ||
|
22 changes: 22 additions & 0 deletions
22
tests/ui/diagnostic_namespace/do_not_recommend/does_not_acccept_args.next.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:10:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default | ||
|
||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:14:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted = "foo")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
--> $DIR/does_not_acccept_args.rs:18:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend(not_accepted(42))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 3 warnings emitted | ||
|
22 changes: 22 additions & 0 deletions
22
tests/ui/diagnostic_namespace/do_not_recommend/does_not_acccept_args.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
trait Foo {} | ||
trait Bar {} | ||
trait Baz {} | ||
|
||
#[diagnostic::do_not_recommend(not_accepted)] | ||
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
impl<T> Foo for T where T: Send {} | ||
|
||
#[diagnostic::do_not_recommend(not_accepted = "foo")] | ||
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
impl<T> Bar for T where T: Send {} | ||
|
||
#[diagnostic::do_not_recommend(not_accepted(42))] | ||
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments | ||
impl<T> Baz for T where T: Send {} | ||
|
||
fn main() {} |
17 changes: 0 additions & 17 deletions
17
tests/ui/diagnostic_namespace/do_not_recommend/feature-gate-do_not_recommend.rs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
tests/ui/diagnostic_namespace/do_not_recommend/feature-gate-do_not_recommend.stderr
This file was deleted.
Oops, something went wrong.
24 changes: 15 additions & 9 deletions
24
..._not_recommend/incorrect-locations.stderr → ...ommend/incorrect-locations.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:4:1 | ||
--> $DIR/incorrect-locations.rs:6:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:8:1 | ||
--> $DIR/incorrect-locations.rs:10:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:12:1 | ||
--> $DIR/incorrect-locations.rs:14:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:16:1 | ||
--> $DIR/incorrect-locations.rs:18:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:20:1 | ||
--> $DIR/incorrect-locations.rs:22:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:24:1 | ||
--> $DIR/incorrect-locations.rs:26:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:28:1 | ||
--> $DIR/incorrect-locations.rs:30:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:32:1 | ||
--> $DIR/incorrect-locations.rs:34:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 8 warnings emitted | ||
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations | ||
--> $DIR/incorrect-locations.rs:38:1 | ||
| | ||
LL | #[diagnostic::do_not_recommend] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 9 warnings emitted | ||
|
Oops, something went wrong.