Skip to content

Commit af54a3e

Browse files
authored
Rollup merge of rust-lang#65359 - Centril:sil, r=davidtwco
simplify integer_lit Extracted from rust-lang#65324. r? @davidtwco
2 parents 5af528a + 7effe63 commit af54a3e

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(proc_macro_internals)]
1818
#![feature(proc_macro_span)]
1919
#![feature(try_trait)]
20+
#![feature(slice_patterns)]
2021
#![feature(unicode_internals)]
2122

2223
#![recursion_limit="256"]

src/libsyntax/parse/literal.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,12 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
426426
let symbol = strip_underscores(symbol);
427427
let s = symbol.as_str();
428428

429-
let mut base = 10;
430-
if s.len() > 1 && s.as_bytes()[0] == b'0' {
431-
match s.as_bytes()[1] {
432-
b'x' => base = 16,
433-
b'o' => base = 8,
434-
b'b' => base = 2,
435-
_ => {}
436-
}
437-
}
429+
let base = match s.as_bytes() {
430+
[b'0', b'x', ..] => 16,
431+
[b'0', b'o', ..] => 8,
432+
[b'0', b'b', ..] => 2,
433+
_ => 10,
434+
};
438435

439436
let ty = match suffix {
440437
Some(suf) => match suf {

0 commit comments

Comments
 (0)