Add as_rchunks (and friends) to slices#78818
Conversation
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
library/core/src/slice/mod.rs
Outdated
There was a problem hiding this comment.
It wasn't obvious to me whether this should be as_chunks_mut_unchecked or as_chunks_unchecked_mut. I could see precedent for both.
There was a problem hiding this comment.
It looks like unchecked_mut is more frequently used but mut_unchecked sounds better to me 😆
There was a problem hiding this comment.
It looks like unchecked_mut has more precedent in slice and iterator APIs so maybe we should roll with that.
I'm very sad that we have a nice mix of both unchecked_mut and mut_unchecked 🥲
src/test/codegen/slice-as_chunks.rs
Outdated
There was a problem hiding this comment.
I wanted to ensure I didn't accidentally introduce extra instructions with the refactor, so codegen test. It did change, but only from lshr/and/and to and/and/lshr exact, which is a thoroughly uninteresting difference.
|
r? @KodrAus |
|
Thanks @scottmcm! r=me with |
|
@bors r=KodrAus |
|
📌 Commit 132307c has been approved by |
Add `as_rchunks` (and friends) to slices `@est31` mentioned (rust-lang#76354 (comment)) that, for completeness, there needed to be an `as_chunks`-like method that chunks from the end (with the remainder at the beginning) like `rchunks` does. So here's a PR for `as_rchunks: &[T] -> (&[T], &[[T; N]])` and `as_rchunks_mut: &mut [T] -> (&mut [T], &mut [[T; N]])`. But as I was doing this and copy-pasting `from_raw_parts` calls, I thought that I should extract that into an unsafe method. It started out a private helper, but it seemed like `as_chunks_unchecked` could be reasonable as a "real" method, so I added docs and made it public. Let me know if you think it doesn't pull its weight.
|
@bors r- This failed in #81085 (comment): The job Click to see the possible cause of the failure (guessed by this bot) |
|
@bors rollup=never Sigh, codegen tests. |
This fixed things the last time I had a problem like this. And plausibly will here too -- the check it's failing on is for the high bit being set in the length of the slice, which is a check that's only in a debug_assert.
|
@bors r=KodrAus |
|
📌 Commit 6bcaba9 has been approved by |
|
☀️ Test successful - checks-actions |
@est31 mentioned (#76354 (comment)) that, for completeness, there needed to be an
as_chunks-like method that chunks from the end (with the remainder at the beginning) likerchunksdoes.So here's a PR for
as_rchunks: &[T] -> (&[T], &[[T; N]])andas_rchunks_mut: &mut [T] -> (&mut [T], &mut [[T; N]]).But as I was doing this and copy-pasting
from_raw_partscalls, I thought that I should extract that into an unsafe method. It started out a private helper, but it seemed likeas_chunks_uncheckedcould be reasonable as a "real" method, so I added docs and made it public. Let me know if you think it doesn't pull its weight.