Uh oh!
There was an error while loading. Please reload this page.
Make some usize-typed masks definitions agnostic to the size of usize - #96081
Conversation
Some masks where defined as ```rust const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; ``` where it was assumed that `usize` is never wider than 64, which is currently true. To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way ```rust const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]); ``` There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
rust-highfive
commented
Apr 15, 2022
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
rust-highfive
commented
Apr 15, 2022
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
usize-typed masks definition agnostic to the size of usizeusize-typed masks definitions agnostic to the size of usizeyaahc
commented
Apr 15, 2022
Sounds good and looks great, thank you for the PR! @bors r+ |
bors
commented
Apr 15, 2022
📌 Commit 93ae6f8 has been approved by |
| #[inline] | ||
| fn contains_nonascii(v: usize) -> bool { | ||
| const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; | ||
| const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; core::mem::size_of::<usize>()]); |
There was a problem hiding this comment.
Why doesn't this use usize::repeat_u8?
EDIT: Oh, I guess that is crate-private.
Rollup of 7 pull requests Successful merges: - rust-lang#95887 (resolve: Create dummy bindings for all unresolved imports) - rust-lang#96023 (couple of clippy::perf fixes) - rust-lang#96035 (Update GitHub Actions actions/checkout Version v2 -> v3) - rust-lang#96038 (docs: add link from zip to unzip) - rust-lang#96047 (:arrow_up: rust-analyzer) - rust-lang#96059 (clarify doc(cfg) wording) - rust-lang#96081 (Make some `usize`-typed masks definitions agnostic to the size of `usize`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Some masks where defined as
where it was assumed that
usizeis never wider than 64, which is currently true.To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an
usize-width-agnostic wayThere are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing
From<usize>foru64.