Skip to content

Commit 547bcf8

Browse files
committed
Auto merge of #15688 - Veykril:rustc_layout_scalar_valid_range, r=Veykril
Make rustc_layout_scalar_valid_range attributes work for non-decimal literals Closes rust-lang/rust-analyzer#15687
2 parents e478db7 + a943b19 commit 547bcf8

File tree

1 file changed

+9
-1
lines changed
  • crates/hir-ty/src/layout

1 file changed

+9
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
119119
let attr = attrs.by_key(name).tt_values();
120120
for tree in attr {
121121
if let Some(it) = tree.token_trees.first() {
122-
if let Ok(it) = it.to_string().parse() {
122+
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,
128+
};
129+
130+
if let Ok(it) = u128::from_str_radix(&text, base) {
123131
return Bound::Included(it);
124132
}
125133
}

0 commit comments

Comments
 (0)