mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Rollup merge of #111584 - nnethercote:number-lexing-tweaks, r=matklad
Number lexing tweaks A couple of improvements to things that puzzled me when I was looking at this code. r? `@matklad`
This commit is contained in:
commit
119b72289b
@ -582,34 +582,38 @@ impl Cursor<'_> {
|
||||
let mut base = Base::Decimal;
|
||||
if first_digit == '0' {
|
||||
// Attempt to parse encoding base.
|
||||
let has_digits = match self.first() {
|
||||
match self.first() {
|
||||
'b' => {
|
||||
base = Base::Binary;
|
||||
self.bump();
|
||||
self.eat_decimal_digits()
|
||||
if !self.eat_decimal_digits() {
|
||||
return Int { base, empty_int: true };
|
||||
}
|
||||
}
|
||||
'o' => {
|
||||
base = Base::Octal;
|
||||
self.bump();
|
||||
self.eat_decimal_digits()
|
||||
if !self.eat_decimal_digits() {
|
||||
return Int { base, empty_int: true };
|
||||
}
|
||||
}
|
||||
'x' => {
|
||||
base = Base::Hexadecimal;
|
||||
self.bump();
|
||||
self.eat_hexadecimal_digits()
|
||||
if !self.eat_hexadecimal_digits() {
|
||||
return Int { base, empty_int: true };
|
||||
}
|
||||
}
|
||||
// Not a base prefix.
|
||||
'0'..='9' | '_' | '.' | 'e' | 'E' => {
|
||||
// Not a base prefix; consume additional digits.
|
||||
'0'..='9' | '_' => {
|
||||
self.eat_decimal_digits();
|
||||
true
|
||||
}
|
||||
|
||||
// Also not a base prefix; nothing more to do here.
|
||||
'.' | 'e' | 'E' => {}
|
||||
|
||||
// Just a 0.
|
||||
_ => return Int { base, empty_int: false },
|
||||
};
|
||||
// Base prefix was provided, but there were no digits
|
||||
// after it, e.g. "0x".
|
||||
if !has_digits {
|
||||
return Int { base, empty_int: true };
|
||||
}
|
||||
} else {
|
||||
// No base prefix, parse number in the usual way.
|
||||
|
Loading…
Reference in New Issue
Block a user