forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#122402 - weiznich:fix/122391, r=compiler-errors Make `#[diagnostic::on_unimplemented]` format string parsing more robust This commit fixes several issues with the format string parsing of the `#[diagnostic::on_unimplemented]` attribute that were pointed out by `@ehuss.` In detail it fixes: * Appearing format specifiers (display, etc). For these we generate a warning that the specifier is unsupported. Otherwise we ignore them * Positional arguments. For these we generate a warning that positional arguments are unsupported in that location and replace them with the format string equivalent (so `{}` or `{n}` where n is the index of the positional argument) * Broken format strings with enclosed }. For these we generate a warning about the broken format string and set the emitted message literally to the provided unformatted string * Unknown format specifiers. For these we generate an additional warning about the unknown specifier. Otherwise we emit the literal string as message. This essentially makes those strings behave like `format!` with the minor difference that we do not generate hard errors but only warnings. After that we continue trying to do something unsuprising (mostly either ignoring the broken parts or falling back to just giving back the literal string as provided). Fix rust-lang#122391 r? `@compiler-errors`
- Loading branch information
Showing
4 changed files
with
382 additions
and
54 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
45 changes: 45 additions & 0 deletions
45
tests/ui/diagnostic_namespace/on_unimplemented/broken_format.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,45 @@ | ||
#[diagnostic::on_unimplemented(message = "{{Test } thing")] | ||
//~^WARN unmatched `}` found | ||
//~|WARN unmatched `}` found | ||
trait ImportantTrait1 {} | ||
|
||
#[diagnostic::on_unimplemented(message = "Test {}")] | ||
//~^WARN positional format arguments are not allowed here | ||
//~|WARN positional format arguments are not allowed here | ||
trait ImportantTrait2 {} | ||
|
||
#[diagnostic::on_unimplemented(message = "Test {1:}")] | ||
//~^WARN positional format arguments are not allowed here | ||
//~|WARN positional format arguments are not allowed here | ||
trait ImportantTrait3 {} | ||
|
||
#[diagnostic::on_unimplemented(message = "Test {Self:123}")] | ||
//~^WARN invalid format specifier | ||
//~|WARN invalid format specifier | ||
trait ImportantTrait4 {} | ||
|
||
#[diagnostic::on_unimplemented(message = "Test {Self:!}")] | ||
//~^WARN expected `'}'`, found `'!'` | ||
//~|WARN expected `'}'`, found `'!'` | ||
//~|WARN unmatched `}` found | ||
//~|WARN unmatched `}` found | ||
trait ImportantTrait5 {} | ||
|
||
fn check_1(_: impl ImportantTrait1) {} | ||
fn check_2(_: impl ImportantTrait2) {} | ||
fn check_3(_: impl ImportantTrait3) {} | ||
fn check_4(_: impl ImportantTrait4) {} | ||
fn check_5(_: impl ImportantTrait5) {} | ||
|
||
fn main() { | ||
check_1(()); | ||
//~^ERROR {{Test } thing | ||
check_2(()); | ||
//~^ERROR Test {} | ||
check_3(()); | ||
//~^ERROR Test {1} | ||
check_4(()); | ||
//~^ERROR Test () | ||
check_5(()); | ||
//~^ERROR Test {Self:!} | ||
} |
Oops, something went wrong.