diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index fc8325e5915..32ae878909f 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -144,7 +144,7 @@ pub struct Parser<'a> { /// `Some(raw count)` when the string is "raw", used to position spans correctly style: Option, /// Start and end byte offset of every successfully parsed argument - pub arg_places: Vec<(usize, usize)>, + pub arg_places: Vec<(SpanIndex, SpanIndex)>, /// Characters that need to be shifted skips: Vec, /// Span offset of the last opening brace seen, used for error reporting @@ -154,7 +154,7 @@ pub struct Parser<'a> { } #[derive(Clone, Copy, Debug)] -pub struct SpanIndex(usize); +pub struct SpanIndex(pub usize); impl SpanIndex { pub fn unwrap(self) -> usize { @@ -166,7 +166,6 @@ impl<'a> Iterator for Parser<'a> { type Item = Piece<'a>; fn next(&mut self) -> Option> { - let raw = self.raw(); if let Some(&(pos, c)) = self.cur.peek() { match c { '{' => { @@ -180,7 +179,7 @@ fn next(&mut self) -> Option> { } else { let arg = self.argument(); if let Some(arg_pos) = self.must_consume('}').map(|end| { - (pos + raw + 1, end + raw + 2) + (self.to_span_index(pos), self.to_span_index(end + 1)) }) { self.arg_places.push(arg_pos); } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 220765fd8c7..17e692d1d32 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -861,7 +861,9 @@ fn find_skips(snippet: &str, is_raw: bool) -> Vec { } let arg_spans = parser.arg_places.iter() - .map(|&(start, end)| fmt.span.from_inner_byte_pos(start, end)) + .map(|&(parse::SpanIndex(start), parse::SpanIndex(end))| { + fmt.span.from_inner_byte_pos(start, end) + }) .collect(); let mut cx = Context { diff --git a/src/test/ui/fmt/format-string-error-2.rs b/src/test/ui/fmt/format-string-error-2.rs index fd6e41ec6fc..3c6c15c06bb 100644 --- a/src/test/ui/fmt/format-string-error-2.rs +++ b/src/test/ui/fmt/format-string-error-2.rs @@ -67,4 +67,6 @@ fn main() { asdf} ", asdf=1); //~^^ ERROR invalid format string + println!("\t{}"); + //~^ ERROR 1 positional argument in format string } diff --git a/src/test/ui/fmt/format-string-error-2.stderr b/src/test/ui/fmt/format-string-error-2.stderr index 0b3f08c1fbe..face0bc0f5f 100644 --- a/src/test/ui/fmt/format-string-error-2.stderr +++ b/src/test/ui/fmt/format-string-error-2.stderr @@ -133,5 +133,11 @@ LL | asdf} | = note: if you intended to print `{`, you can escape it using `{{` -error: aborting due to 13 previous errors +error: 1 positional argument in format string, but no arguments were given + --> $DIR/format-string-error-2.rs:70:17 + | +LL | println!("/t{}"); + | ^^ + +error: aborting due to 14 previous errors