-
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.
Auto merge of #106195 - Nilstrieb:no-more-being-clueless-whether-it-r…
…eally-is-a-literal, r=compiler-errors Improve heuristics whether `format_args` string is a source literal Previously, it only checked whether there was _a_ literal at the span of the first argument, not whether the literal actually matched up. This caused issues when a proc macro was generating a different literal with the same span. This requires an annoying special case for literals ending in `\n` because otherwise `println` wouldn't give detailed diagnostics anymore which would be bad. Fixes #106191
- Loading branch information
Showing
5 changed files
with
105 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// aux-build:format-string-proc-macro.rs | ||
|
||
extern crate format_string_proc_macro; | ||
|
||
fn main() { | ||
format_string_proc_macro::respan_to_invalid_format_literal!("¡"); | ||
//~^ ERROR invalid format string: expected `'}'` but string was terminated | ||
format_args!(r#concat!("¡ {")); | ||
//~^ ERROR invalid format string: expected `'}'` but string was terminated | ||
} |
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,19 @@ | ||
error: invalid format string: expected `'}'` but string was terminated | ||
--> $DIR/respanned-literal-issue-106191.rs:6:65 | ||
| | ||
LL | format_string_proc_macro::respan_to_invalid_format_literal!("¡"); | ||
| ^^^ expected `'}'` in format string | ||
| | ||
= note: if you intended to print `{`, you can escape it using `{{` | ||
|
||
error: invalid format string: expected `'}'` but string was terminated | ||
--> $DIR/respanned-literal-issue-106191.rs:8:18 | ||
| | ||
LL | format_args!(r#concat!("¡ {")); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `'}'` in format string | ||
| | ||
= note: if you intended to print `{`, you can escape it using `{{` | ||
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|