mirror of https://github.com/rust-lang/rust.git
Rollup merge of #83343 - osa1:issue83340, r=jackh726
Simplify and fix byte skipping in format! string parser Fixes '\\' handling in format strings. Fixes #83340
This commit is contained in:
commit
d7216bae23
|
@ -735,25 +735,24 @@ fn find_skips_from_snippet(
|
||||||
};
|
};
|
||||||
|
|
||||||
fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
|
fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
|
||||||
let mut eat_ws = false;
|
|
||||||
let mut s = snippet.char_indices().peekable();
|
let mut s = snippet.char_indices().peekable();
|
||||||
let mut skips = vec![];
|
let mut skips = vec![];
|
||||||
while let Some((pos, c)) = s.next() {
|
while let Some((pos, c)) = s.next() {
|
||||||
match (c, s.peek()) {
|
match (c, s.peek()) {
|
||||||
// skip whitespace and empty lines ending in '\\'
|
// skip whitespace and empty lines ending in '\\'
|
||||||
('\\', Some((next_pos, '\n'))) if !is_raw => {
|
('\\', Some((next_pos, '\n'))) if !is_raw => {
|
||||||
eat_ws = true;
|
|
||||||
skips.push(pos);
|
skips.push(pos);
|
||||||
skips.push(*next_pos);
|
skips.push(*next_pos);
|
||||||
let _ = s.next();
|
let _ = s.next();
|
||||||
}
|
|
||||||
('\\', Some((next_pos, '\n' | 'n' | 't'))) if eat_ws => {
|
while let Some((pos, c)) = s.peek() {
|
||||||
skips.push(pos);
|
if matches!(c, ' ' | '\n' | '\t') {
|
||||||
skips.push(*next_pos);
|
skips.push(*pos);
|
||||||
let _ = s.next();
|
let _ = s.next();
|
||||||
}
|
} else {
|
||||||
(' ' | '\n' | '\t', _) if eat_ws => {
|
break;
|
||||||
skips.push(pos);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
|
('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
|
||||||
skips.push(*next_pos);
|
skips.push(*next_pos);
|
||||||
|
@ -804,10 +803,6 @@ fn find_skips_from_snippet(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ if eat_ws => {
|
|
||||||
// `take_while(|c| c.is_whitespace())`
|
|
||||||
eat_ws = false;
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// check-fail
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!(
|
||||||
|
"\
|
||||||
|
\n {} │", //~ ERROR: 1 positional argument in format string, but no arguments were given
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
error: 1 positional argument in format string, but no arguments were given
|
||||||
|
--> $DIR/issue-83340.rs:6:4
|
||||||
|
|
|
||||||
|
LL | \n {} │",
|
||||||
|
| ^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue