forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#117742 - weiznich:turn_overlapping_diagnostic…
…_options_into_warnings, r=compiler-errors Add some additional warnings for duplicated diagnostic items This commit adds warnings if a user supplies several diagnostic options where we can only apply one of them. We explicitly warn about ignored options here. In addition a small test for these warnings is added. r? `@compiler-errors` For now that's the last PR to improve the warnings generated by misused `#[diagnostic::on_unimplemented]` attributes. I'm not sure what needs to be done next to move this closer to stabilization.
- Loading branch information
Showing
7 changed files
with
219 additions
and
17 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
25 changes: 25 additions & 0 deletions
25
tests/ui/diagnostic_namespace/on_unimplemented/report_warning_on_duplicated_options.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,25 @@ | ||
#![feature(diagnostic_namespace)] | ||
|
||
#[diagnostic::on_unimplemented( | ||
message = "first message", | ||
label = "first label", | ||
note = "custom note" | ||
)] | ||
#[diagnostic::on_unimplemented( | ||
message = "second message", | ||
//~^WARN `message` is ignored due to previous definition of `message` | ||
//~|WARN `message` is ignored due to previous definition of `message` | ||
label = "second label", | ||
//~^WARN `label` is ignored due to previous definition of `label` | ||
//~|WARN `label` is ignored due to previous definition of `label` | ||
note = "second note" | ||
)] | ||
trait Foo {} | ||
|
||
|
||
fn takes_foo(_: impl Foo) {} | ||
|
||
fn main() { | ||
takes_foo(()); | ||
//~^ERROR first message | ||
} |
67 changes: 67 additions & 0 deletions
67
tests/ui/diagnostic_namespace/on_unimplemented/report_warning_on_duplicated_options.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,67 @@ | ||
warning: `message` is ignored due to previous definition of `message` | ||
--> $DIR/report_warning_on_duplicated_options.rs:9:5 | ||
| | ||
LL | message = "first message", | ||
| ------------------------- `message` is first declared here | ||
... | ||
LL | message = "second message", | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `message` is already declared here | ||
| | ||
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default | ||
|
||
warning: `label` is ignored due to previous definition of `label` | ||
--> $DIR/report_warning_on_duplicated_options.rs:12:5 | ||
| | ||
LL | label = "first label", | ||
| --------------------- `label` is first declared here | ||
... | ||
LL | label = "second label", | ||
| ^^^^^^^^^^^^^^^^^^^^^^ `label` is already declared here | ||
|
||
warning: `message` is ignored due to previous definition of `message` | ||
--> $DIR/report_warning_on_duplicated_options.rs:9:5 | ||
| | ||
LL | message = "first message", | ||
| ------------------------- `message` is first declared here | ||
... | ||
LL | message = "second message", | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `message` is already declared here | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
warning: `label` is ignored due to previous definition of `label` | ||
--> $DIR/report_warning_on_duplicated_options.rs:12:5 | ||
| | ||
LL | label = "first label", | ||
| --------------------- `label` is first declared here | ||
... | ||
LL | label = "second label", | ||
| ^^^^^^^^^^^^^^^^^^^^^^ `label` is already declared here | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0277]: first message | ||
--> $DIR/report_warning_on_duplicated_options.rs:23:15 | ||
| | ||
LL | takes_foo(()); | ||
| --------- ^^ first label | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Foo` is not implemented for `()` | ||
= note: custom note | ||
= note: second note | ||
help: this trait has no implementations, consider adding one | ||
--> $DIR/report_warning_on_duplicated_options.rs:17:1 | ||
| | ||
LL | trait Foo {} | ||
| ^^^^^^^^^ | ||
note: required by a bound in `takes_foo` | ||
--> $DIR/report_warning_on_duplicated_options.rs:20:22 | ||
| | ||
LL | fn takes_foo(_: impl Foo) {} | ||
| ^^^ required by this bound in `takes_foo` | ||
|
||
error: aborting due to previous error; 4 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |