fix incorrect position of chars in fmt str
This commit is contained in:
parent
85da68cb6d
commit
052159be53
|
@ -169,10 +169,9 @@ impl<'a> Iterator for Parser<'a> {
|
||||||
if let Some(&(pos, c)) = self.cur.peek() {
|
if let Some(&(pos, c)) = self.cur.peek() {
|
||||||
match c {
|
match c {
|
||||||
'{' => {
|
'{' => {
|
||||||
let pos = pos + raw + 1;
|
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
if self.consume('{') {
|
if self.consume('{') {
|
||||||
Some(String(self.string(pos)))
|
Some(String(self.string(pos + 1)))
|
||||||
} else {
|
} else {
|
||||||
let ret = Some(NextArgument(self.argument()));
|
let ret = Some(NextArgument(self.argument()));
|
||||||
self.must_consume('}');
|
self.must_consume('}');
|
||||||
|
@ -180,17 +179,17 @@ impl<'a> Iterator for Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'}' => {
|
'}' => {
|
||||||
let pos = pos + raw + 1;
|
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
if self.consume('}') {
|
if self.consume('}') {
|
||||||
Some(String(self.string(pos)))
|
Some(String(self.string(pos + 1)))
|
||||||
} else {
|
} else {
|
||||||
|
let err_pos = pos + raw + 1;
|
||||||
self.err_with_note(
|
self.err_with_note(
|
||||||
"unmatched `}` found",
|
"unmatched `}` found",
|
||||||
"unmatched `}`",
|
"unmatched `}`",
|
||||||
"if you intended to print `}`, you can escape it using `}}`",
|
"if you intended to print `}`, you can escape it using `}}`",
|
||||||
pos,
|
err_pos,
|
||||||
pos,
|
err_pos,
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -283,15 +282,17 @@ impl<'a> Parser<'a> {
|
||||||
syntax::ast::StrStyle::Raw(raw) => raw as usize,
|
syntax::ast::StrStyle::Raw(raw) => raw as usize,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let padding = raw + self.seen_newlines;
|
let padding = raw + self.seen_newlines;
|
||||||
if let Some(&(pos, maybe)) = self.cur.peek() {
|
if let Some(&(pos, maybe)) = self.cur.peek() {
|
||||||
if c == maybe {
|
if c == maybe {
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
} else {
|
} else {
|
||||||
|
let pos = pos + padding + 1;
|
||||||
self.err(format!("expected `{:?}`, found `{:?}`", c, maybe),
|
self.err(format!("expected `{:?}`, found `{:?}`", c, maybe),
|
||||||
format!("expected `{}`", c),
|
format!("expected `{}`", c),
|
||||||
pos + padding + 1,
|
pos,
|
||||||
pos + padding + 1);
|
pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let msg = format!("expected `{:?}` but string was terminated", c);
|
let msg = format!("expected `{:?}` but string was terminated", c);
|
||||||
|
|
Loading…
Reference in New Issue