-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #116642 - weiznich:diagnostic_on_unimplemented_improv…
…ements, r=compiler-errors Handle several `#[diagnostic::on_unimplemented]` attributes correctly This PR fixes an issues where rustc would ignore subsequent `#[diagnostic::on_unimplemented]` attributes. The [corresponding RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html) specifies that the first matching instance of each option is used. Invalid attributes are linted and otherwise ignored.
- Loading branch information
Showing
3 changed files
with
108 additions
and
12 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
22 changes: 22 additions & 0 deletions
22
...tic_namespace/on_unimplemented/ignore_unsupported_options_and_continue_to_use_fallback.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 @@ | ||
#![feature(diagnostic_namespace)] | ||
|
||
#[diagnostic::on_unimplemented( | ||
//~^WARN malformed `on_unimplemented` attribute | ||
//~|WARN malformed `on_unimplemented` attribute | ||
if(Self = ()), | ||
message = "not used yet", | ||
label = "not used yet", | ||
note = "not used yet" | ||
)] | ||
#[diagnostic::on_unimplemented(message = "fallback!!")] | ||
#[diagnostic::on_unimplemented(label = "fallback label")] | ||
#[diagnostic::on_unimplemented(note = "fallback note")] | ||
#[diagnostic::on_unimplemented(message = "fallback2!!")] | ||
trait Foo {} | ||
|
||
fn takes_foo(_: impl Foo) {} | ||
|
||
fn main() { | ||
takes_foo(()); | ||
//~^ERROR fallback!! | ||
} |
52 changes: 52 additions & 0 deletions
52
...namespace/on_unimplemented/ignore_unsupported_options_and_continue_to_use_fallback.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,52 @@ | ||
warning: malformed `on_unimplemented` attribute | ||
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:3:1 | ||
| | ||
LL | / #[diagnostic::on_unimplemented( | ||
LL | | | ||
LL | | | ||
LL | | if(Self = ()), | ||
... | | ||
LL | | note = "not used yet" | ||
LL | | )] | ||
| |__^ | ||
| | ||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default | ||
|
||
warning: malformed `on_unimplemented` attribute | ||
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:3:1 | ||
| | ||
LL | / #[diagnostic::on_unimplemented( | ||
LL | | | ||
LL | | | ||
LL | | if(Self = ()), | ||
... | | ||
LL | | note = "not used yet" | ||
LL | | )] | ||
| |__^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0277]: fallback!! | ||
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:20:15 | ||
| | ||
LL | takes_foo(()); | ||
| --------- ^^ fallback label | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Foo` is not implemented for `()` | ||
= note: fallback note | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:15:1 | ||
| | ||
LL | trait Foo {} | ||
| ^^^^^^^^^ | ||
note: required by a bound in `takes_foo` | ||
--> $DIR/ignore_unsupported_options_and_continue_to_use_fallback.rs:17:22 | ||
| | ||
LL | fn takes_foo(_: impl Foo) {} | ||
| ^^^ required by this bound in `takes_foo` | ||
|
||
error: aborting due to previous error; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |