Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #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
bors 2023-10-02
parent 0840038 · parent 084ee93 · commit d7faec8
-rw-r--r--crates/hir-ty/src/layout/adt.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs
index 457b227427..c2778b9a8e 100644
--- a/crates/hir-ty/src/layout/adt.rs
+++ b/crates/hir-ty/src/layout/adt.rs
@@ -120,14 +120,14 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
for tree in attr {
if let Some(it) = tree.token_trees.first() {
let text = it.to_string().replace('_', "");
- let base = match text.as_bytes() {
- [b'0', b'x', ..] => 16,
- [b'0', b'o', ..] => 8,
- [b'0', b'b', ..] => 2,
- _ => 10,
+ let (text, base) = match text.as_bytes() {
+ [b'0', b'x', ..] => (&text[2..], 16),
+ [b'0', b'o', ..] => (&text[2..], 8),
+ [b'0', b'b', ..] => (&text[2..], 2),
+ _ => (&*text, 10),
};
- if let Ok(it) = u128::from_str_radix(&text, base) {
+ if let Ok(it) = u128::from_str_radix(text, base) {
return Bound::Included(it);
}
}