diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 2a38464d7c1ee..7d87c1839d78c 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -288,7 +288,7 @@ impl<'a> Parser<'a> { self.cur.next(); Some(pos) } else { - let pos = pos + padding + 1; + let pos = pos + raw + 1; self.err(format!("expected `{:?}`, found `{:?}`", c, maybe), format!("expected `{}`", c), pos, diff --git a/src/test/ui/if/ifmt-bad-arg.rs b/src/test/ui/if/ifmt-bad-arg.rs index bbd75f30d6cb1..6f051b40e8b65 100644 --- a/src/test/ui/if/ifmt-bad-arg.rs +++ b/src/test/ui/if/ifmt-bad-arg.rs @@ -71,4 +71,18 @@ fn main() { "##); //~^^^ ERROR: there is no argument named `foo` + + // bad syntax in format string with multiple newlines, #53836 + format!("first number: {} +second number: {} +third number: {} +fourth number: {} +fifth number: {} +sixth number: {} +seventh number: {} +eighth number: {} +ninth number: { +tenth number: {}", + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + //~^^ ERROR: invalid format string } diff --git a/src/test/ui/if/ifmt-bad-arg.stderr b/src/test/ui/if/ifmt-bad-arg.stderr index c8fd8bad19ba5..7e71707c22b16 100644 --- a/src/test/ui/if/ifmt-bad-arg.stderr +++ b/src/test/ui/if/ifmt-bad-arg.stderr @@ -204,5 +204,11 @@ error: there is no argument named `foo` LL | {foo} | ^^^^^ -error: aborting due to 27 previous errors +error: invalid format string: expected `'}'`, found `'t'` + --> $DIR/ifmt-bad-arg.rs:85:1 + | +LL | tenth number: {}", + | ^ expected `}` in format string + +error: aborting due to 28 previous errors