diff options
| author | bors <bors@rust-lang.org> | 2023-09-29 13:32:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-29 13:32:09 +0000 |
| commit | 547bcf8bbfec9f29263452786ff6c1d6ebc1b90f (patch) | |
| tree | ff9b93cdb5350c1de67008c777d9bd7d6c2da3b0 | |
| parent | e478db717e3b4531d226f8428c4255e350a3f232 (diff) | |
| parent | a943b19e0865a7a1bf1ad0562c2e3426ba9bd22d (diff) | |
| download | rust-547bcf8bbfec9f29263452786ff6c1d6ebc1b90f.tar.gz rust-547bcf8bbfec9f29263452786ff6c1d6ebc1b90f.zip | |
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 https://github.com/rust-lang/rust-analyzer/issues/15687
| -rw-r--r-- | crates/hir-ty/src/layout/adt.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs index 85ef649b895..457b227427e 100644 --- a/crates/hir-ty/src/layout/adt.rs +++ b/crates/hir-ty/src/layout/adt.rs @@ -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); } } |
