Fix span calculation in format strings
This commit is contained in:
parent
022720bfcc
commit
14f3ec2815
5 changed files with 57 additions and 1 deletions
15
src/test/ui/fmt/format-concat-span.rs
Normal file
15
src/test/ui/fmt/format-concat-span.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// If the format string is another macro invocation, rustc would previously
|
||||
// compute nonsensical spans, such as:
|
||||
//
|
||||
// error: invalid format string: unmatched `}` found
|
||||
// --> test.rs:2:17
|
||||
// |
|
||||
// 2 | format!(concat!("abc}"));
|
||||
// | ^ unmatched `}` in format string
|
||||
//
|
||||
// This test checks that this behavior has been fixed.
|
||||
|
||||
fn main() {
|
||||
format!(concat!("abc}"));
|
||||
//~^ ERROR: invalid format string: unmatched `}` found
|
||||
}
|
||||
11
src/test/ui/fmt/format-concat-span.stderr
Normal file
11
src/test/ui/fmt/format-concat-span.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: invalid format string: unmatched `}` found
|
||||
--> $DIR/format-concat-span.rs:13:13
|
||||
|
|
||||
LL | format!(concat!("abc}"));
|
||||
| ^^^^^^^^^^^^^^^ unmatched `}` 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 previous error
|
||||
|
||||
6
src/test/ui/fmt/issue-86085.rs
Normal file
6
src/test/ui/fmt/issue-86085.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Tests for an ICE with the fuzzed input below.
|
||||
|
||||
fn main ( ) {
|
||||
format ! ( concat ! ( r#"lJÆ<F0908FBF>.<>"# , "r} {}" ) ) ;
|
||||
//~^ ERROR: invalid format string: unmatched `}` found
|
||||
}
|
||||
11
src/test/ui/fmt/issue-86085.stderr
Normal file
11
src/test/ui/fmt/issue-86085.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: invalid format string: unmatched `}` found
|
||||
--> $DIR/issue-86085.rs:4:12
|
||||
|
|
||||
LL | format ! ( concat ! ( r#"lJÆ<F0908FBF>.<>"# , "r} {}" ) ) ;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unmatched `}` 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 previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue