Skip to content

Commit 052159b

Browse files
author
Esteban Küber
committed
fix incorrect position of chars in fmt str
1 parent 85da68c commit 052159b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/libfmt_macros/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,27 @@ impl<'a> Iterator for Parser<'a> {
169169
if let Some(&(pos, c)) = self.cur.peek() {
170170
match c {
171171
'{' => {
172-
let pos = pos + raw + 1;
173172
self.cur.next();
174173
if self.consume('{') {
175-
Some(String(self.string(pos)))
174+
Some(String(self.string(pos + 1)))
176175
} else {
177176
let ret = Some(NextArgument(self.argument()));
178177
self.must_consume('}');
179178
ret
180179
}
181180
}
182181
'}' => {
183-
let pos = pos + raw + 1;
184182
self.cur.next();
185183
if self.consume('}') {
186-
Some(String(self.string(pos)))
184+
Some(String(self.string(pos + 1)))
187185
} else {
186+
let err_pos = pos + raw + 1;
188187
self.err_with_note(
189188
"unmatched `}` found",
190189
"unmatched `}`",
191190
"if you intended to print `}`, you can escape it using `}}`",
192-
pos,
193-
pos,
191+
err_pos,
192+
err_pos,
194193
);
195194
None
196195
}
@@ -283,15 +282,17 @@ impl<'a> Parser<'a> {
283282
syntax::ast::StrStyle::Raw(raw) => raw as usize,
284283
_ => 0,
285284
};
285+
286286
let padding = raw + self.seen_newlines;
287287
if let Some(&(pos, maybe)) = self.cur.peek() {
288288
if c == maybe {
289289
self.cur.next();
290290
} else {
291+
let pos = pos + padding + 1;
291292
self.err(format!("expected `{:?}`, found `{:?}`", c, maybe),
292293
format!("expected `{}`", c),
293-
pos + padding + 1,
294-
pos + padding + 1);
294+
pos,
295+
pos);
295296
}
296297
} else {
297298
let msg = format!("expected `{:?}` but string was terminated", c);

0 commit comments

Comments
 (0)