summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-05-15 16:41:32 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2023-05-15 18:30:26 +1000
commit19967c5890851148800886e3770fb45fb4b9ff90 (patch)
treec75e6d539bf48c3beb60bad6ba0c0e568ea09f42 /compiler
parent18bfe5d8a9ca0e226171e98f8f4ef071790f3352 (diff)
downloadrust-19967c5890851148800886e3770fb45fb4b9ff90.tar.gz
Make `Cursor::number` less DRY.
A tiny bit of repetition makes this easier to read, and avoids a test on the "Not a base prefix" match arm.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lexer/src/lib.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs
index c07dc19a0ac..30b7686314e 100644
--- a/compiler/rustc_lexer/src/lib.rs
+++ b/compiler/rustc_lexer/src/lib.rs
@@ -582,34 +582,34 @@ 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' => {
self.eat_decimal_digits();
- true
}
// 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.