Skip to content

Add Vec::into_chunks - #142138

Merged
bors merged 4 commits into
rust-lang:masterfrom
ashivaram23:vec_into_chunks
Jul 2, 2025
Merged

Add Vec::into_chunks#142138
bors merged 4 commits into
rust-lang:masterfrom
ashivaram23:vec_into_chunks

Conversation

@ashivaram23

@ashivaram23ashivaram23 commented Jun 7, 2025

Copy link
Copy Markdown
Contributor

Tracking issue #142137

@rustbot

Copy link
Copy Markdown
Collaborator

r? @thomcc

rustbot has assigned @thomcc.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 7, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment threadlibrary/alloc/src/vec/mod.rs Outdated
#[unstable(feature = "vec_into_chunks", issue = "142137")]
pub fn into_chunks<const N: usize>(mut self) -> Vec<[T; N], A> {
const {
assert!(N != 0, "chunk size should be greater than zero");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

language nit: "must be" instead of "should be", as this is not an advisory suggestion.

Comment on lines +3036 to +3044
let len_remainder = len % N;
if len_remainder != 0 {
self.truncate(len - len_remainder);
}

let cap_remainder = cap % N;
if !T::IS_ZST && cap_remainder != 0 {
self.buf.shrink_to_fit(cap - cap_remainder);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating whether the != 0 checks here are useful, since the methods called will immediately do similar checks, but I think I ended up at 🤷 might as well leave it as-is.

@scottmcm

Copy link
Copy Markdown
Member

I'm personally unsure about whether the infallible-but-possible-reallocating version is the right thing to do for this API, but it matches the ACP so that sounds like a tracking issue problem, not a this-PR problem.

Code change itself looks good to me, so
@bors r+ rollup
r? scottmcm

@bors

bors commented Jul 1, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit c1d32d8 has been approved by scottmcm

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 1, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 1, 2025
@jhprattjhpratt mentioned this pull request Jul 1, 2025
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 12 pull requests
Successful merges:
- #141829 (Specialize sleep_until implementation for unix (except mac))
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142568 (Use the .drectve section for exporting symbols from dlls on Windows)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143038 (avoid suggesting traits from private dependencies)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143206 (Align attr fixes)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 2, 2025
@jhprattjhpratt mentioned this pull request Jul 2, 2025
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 11 pull requests
Successful merges:
- #141829 (Specialize sleep_until implementation for unix (except mac))
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143038 (avoid suggesting traits from private dependencies)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143206 (Align attr fixes)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 2, 2025
@jhprattjhpratt mentioned this pull request Jul 2, 2025
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 12 pull requests
Successful merges:
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143038 (avoid suggesting traits from private dependencies)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143206 (Align attr fixes)
- #143231 (Suggest use another lifetime specifier instead of underscore lifetime)
- #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 2, 2025
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 11 pull requests
Successful merges:
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143038 (avoid suggesting traits from private dependencies)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143231 (Suggest use another lifetime specifier instead of underscore lifetime)
- #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 2, 2025
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 10 pull requests
Successful merges:
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143231 (Suggest use another lifetime specifier instead of underscore lifetime)
- #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 9 pull requests
Successful merges:
- #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
- #142138 (Add `Vec::into_chunks`)
- #142321 (Expose elf abi on ppc64 targets)
- #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
- #143194 (fix bitcast of single-element SIMD vectors)
- #143231 (Suggest use another lifetime specifier instead of underscore lifetime)
- #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest)
- #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
- #143274 (ci: support optional jobs)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 6a31e69 into rust-lang:masterJul 2, 2025
@rustbotrustbot added this to the 1.90.0 milestone Jul 2, 2025
rust-timer added a commit that referenced this pull request Jul 2, 2025
Rollup merge of #142138 - ashivaram23:vec_into_chunks, r=scottmcm
Add `Vec::into_chunks`
Tracking issue #142137
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jul 11, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@ashivaram23@rustbot@rust-log-analyzer@scottmcm@bors@lukaslueg@thomcc