Skip to content

Commit d7faec8

Browse files
committed
Auto merge of rust-lang#15701 - lnicola:rustc_layout_scalar_valid_range2, r=lnicola
fix: strip base prefix in `layout_scalar_valid_range` CC https://github.com/rust-lang/rust-analyzer/pull/15688/files#r1342311078
2 parents 0840038 + 084ee93 commit d7faec8

File tree

1 file changed

+6
-6
lines changed
  • crates/hir-ty/src/layout

1 file changed

+6
-6
lines changed

crates/hir-ty/src/layout/adt.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
120120
for tree in attr {
121121
if let Some(it) = tree.token_trees.first() {
122122
let text = it.to_string().replace('_', "");
123-
let base = match text.as_bytes() {
124-
[b'0', b'x', ..] => 16,
125-
[b'0', b'o', ..] => 8,
126-
[b'0', b'b', ..] => 2,
127-
_ => 10,
123+
let (text, base) = match text.as_bytes() {
124+
[b'0', b'x', ..] => (&text[2..], 16),
125+
[b'0', b'o', ..] => (&text[2..], 8),
126+
[b'0', b'b', ..] => (&text[2..], 2),
127+
_ => (&*text, 10),
128128
};
129129

130-
if let Ok(it) = u128::from_str_radix(&text, base) {
130+
if let Ok(it) = u128::from_str_radix(text, base) {
131131
return Bound::Included(it);
132132
}
133133
}

0 commit comments

Comments
 (0)