Skip to content

Commit 19967c5

Browse files
committed
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.
1 parent 18bfe5d commit 19967c5

File tree

1 file changed

+10
-10
lines changed
  • compiler/rustc_lexer/src

1 file changed

+10
-10
lines changed

compiler/rustc_lexer/src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -582,34 +582,34 @@ impl Cursor<'_> {
582582
let mut base = Base::Decimal;
583583
if first_digit == '0' {
584584
// Attempt to parse encoding base.
585-
let has_digits = match self.first() {
585+
match self.first() {
586586
'b' => {
587587
base = Base::Binary;
588588
self.bump();
589-
self.eat_decimal_digits()
589+
if !self.eat_decimal_digits() {
590+
return Int { base, empty_int: true };
591+
}
590592
}
591593
'o' => {
592594
base = Base::Octal;
593595
self.bump();
594-
self.eat_decimal_digits()
596+
if !self.eat_decimal_digits() {
597+
return Int { base, empty_int: true };
598+
}
595599
}
596600
'x' => {
597601
base = Base::Hexadecimal;
598602
self.bump();
599-
self.eat_hexadecimal_digits()
603+
if !self.eat_hexadecimal_digits() {
604+
return Int { base, empty_int: true };
605+
}
600606
}
601607
// Not a base prefix.
602608
'0'..='9' | '_' | '.' | 'e' | 'E' => {
603609
self.eat_decimal_digits();
604-
true
605610
}
606611
// Just a 0.
607612
_ => return Int { base, empty_int: false },
608-
};
609-
// Base prefix was provided, but there were no digits
610-
// after it, e.g. "0x".
611-
if !has_digits {
612-
return Int { base, empty_int: true };
613613
}
614614
} else {
615615
// No base prefix, parse number in the usual way.

0 commit comments

Comments
 (0)