about summary refs log tree commit diff
path: root/compiler/rustc_parse_format
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2021-03-21 14:27:22 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2021-03-21 14:42:27 +0300
commitae8ef70a499907c929f5d7ad6539cd1187da336b (patch)
tree079a3a4f04995dd6f871104bc1b5880300be5373 /compiler/rustc_parse_format
parentbbf07c0b4f210ced7bd2785ab554e0d805644235 (diff)
downloadrust-ae8ef70a499907c929f5d7ad6539cd1187da336b.tar.gz
rust-ae8ef70a499907c929f5d7ad6539cd1187da336b.zip
Simplify and fix byte skipping in format! string parser
Fixes '\\' handling in format strings.

Fixes #83340
Diffstat (limited to 'compiler/rustc_parse_format')
-rw-r--r--compiler/rustc_parse_format/src/lib.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs
index 92d974690b5..e20fc28e794 100644
--- a/compiler/rustc_parse_format/src/lib.rs
+++ b/compiler/rustc_parse_format/src/lib.rs
@@ -735,25 +735,24 @@ fn find_skips_from_snippet(
     };
 
     fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
-        let mut eat_ws = false;
         let mut s = snippet.char_indices().peekable();
         let mut skips = vec![];
         while let Some((pos, c)) = s.next() {
             match (c, s.peek()) {
                 // skip whitespace and empty lines ending in '\\'
                 ('\\', Some((next_pos, '\n'))) if !is_raw => {
-                    eat_ws = true;
                     skips.push(pos);
                     skips.push(*next_pos);
                     let _ = s.next();
-                }
-                ('\\', Some((next_pos, '\n' | 'n' | 't'))) if eat_ws => {
-                    skips.push(pos);
-                    skips.push(*next_pos);
-                    let _ = s.next();
-                }
-                (' ' | '\n' | '\t', _) if eat_ws => {
-                    skips.push(pos);
+
+                    while let Some((pos, c)) = s.peek() {
+                        if matches!(c, ' ' | '\n' | '\t') {
+                            skips.push(*pos);
+                            let _ = s.next();
+                        } else {
+                            break;
+                        }
+                    }
                 }
                 ('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
                     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;
-                }
                 _ => {}
             }
         }