summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-11-04 10:02:29 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2022-11-04 14:24:41 +1100
commita203482d2a20cba0c86298334ebd74438bd477ba (patch)
tree33ce0a61da56470c5a5242eca33f887b64fc1656 /compiler/rustc_parse/src
parentd963686f5a87b9eaa2ac2bdc29ddb796e0e83f1f (diff)
downloadrust-a203482d2a20cba0c86298334ebd74438bd477ba.tar.gz
rust-a203482d2a20cba0c86298334ebd74438bd477ba.zip
Inline and remove `validate_int_literal`.
It has a single callsite, and is fairly small. The `Float` match arm
already has base-specific checking inline, so this makes things more
consistent.
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs31
1 files changed, 13 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index 61b5be42404..9de0c74f4b1 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -437,7 +437,19 @@ impl<'a> StringReader<'a> {
                         .emit();
                     (token::Integer, sym::integer(0))
                 } else {
-                    self.validate_int_literal(base, start, end);
+                    if matches!(base, Base::Binary | Base::Octal) {
+                        let base = base as u32;
+                        let s = self.str_from_to(start + BytePos(2), end);
+                        for (idx, c) in s.char_indices() {
+                            if c != '_' && c.to_digit(base).is_none() {
+                                self.err_span_(
+                                    start + BytePos::from_usize(2 + idx),
+                                    start + BytePos::from_usize(2 + idx + c.len_utf8()),
+                                    &format!("invalid digit for a base {} literal", base),
+                                );
+                            }
+                        }
+                    }
                     (token::Integer, self.symbol_from_to(start, end))
                 }
             }
@@ -683,23 +695,6 @@ impl<'a> StringReader<'a> {
         });
         (kind, Symbol::intern(lit_content))
     }
-
-    fn validate_int_literal(&self, base: Base, content_start: BytePos, content_end: BytePos) {
-        let base = match base {
-            Base::Binary => 2,
-            Base::Octal => 8,
-            _ => return,
-        };
-        let s = self.str_from_to(content_start + BytePos(2), content_end);
-        for (idx, c) in s.char_indices() {
-            let idx = idx as u32;
-            if c != '_' && c.to_digit(base).is_none() {
-                let lo = content_start + BytePos(2 + idx);
-                let hi = content_start + BytePos(2 + idx + c.len_utf8() as u32);
-                self.err_span_(lo, hi, &format!("invalid digit for a base {} literal", base));
-            }
-        }
-    }
 }
 
 pub fn nfc_normalize(string: &str) -> Symbol {