Skip to content

Commit

Permalink
Auto merge of #15688 - Veykril:rustc_layout_scalar_valid_range, r=Vey…
Browse files Browse the repository at this point in the history
…kril

Make rustc_layout_scalar_valid_range attributes work for non-decimal literals

Closes rust-lang/rust-analyzer#15687
  • Loading branch information
bors committed Sep 29, 2023
2 parents e478db7 + a943b19 commit 547bcf8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/hir-ty/src/layout/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
let attr = attrs.by_key(name).tt_values();
for tree in attr {
if let Some(it) = tree.token_trees.first() {
if let Ok(it) = it.to_string().parse() {
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,
};

if let Ok(it) = u128::from_str_radix(&text, base) {
return Bound::Included(it);
}
}
Expand Down

0 comments on commit 547bcf8

Please sign in to comment.