mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-30 16:43:41 +00:00
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.
This commit is contained in:
parent
d963686f5a
commit
a203482d2a
@ -203,13 +203,13 @@ pub enum RawStrError {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Base {
|
||||
/// Literal starts with "0b".
|
||||
Binary,
|
||||
Binary = 2,
|
||||
/// Literal starts with "0o".
|
||||
Octal,
|
||||
/// Literal starts with "0x".
|
||||
Hexadecimal,
|
||||
Octal = 8,
|
||||
/// Literal doesn't contain a prefix.
|
||||
Decimal,
|
||||
Decimal = 10,
|
||||
/// Literal starts with "0x".
|
||||
Hexadecimal = 16,
|
||||
}
|
||||
|
||||
/// `rustc` allows files to have a shebang, e.g. "#!/usr/bin/rustrun",
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user