Skip to content

Conversation

@jdonszelmann
Copy link
Contributor

As per #149266

@rustbot rustbot 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 Nov 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

@jdonszelmann
Copy link
Contributor Author

Implementing exactly_one in terms of collect_array seems to generate the exact same code as a dedicated implementation:
https://godbolt.org/z/Tc6P5MhrE

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from 050e278 to 1e50c8a Compare November 24, 2025 13:27
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from 1e50c8a to 6b0bbcc Compare November 24, 2025 13:34
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from 6b0bbcc to 710c1d4 Compare November 24, 2025 14:12
@jdonszelmann
Copy link
Contributor Author

As you can see from the 2nd commit and the CI failures, since exactly_one conflicts with itertools we get some FCWs. How do we usually deal with those? I doubt this is the first iterator method that also already existed in itertools.

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from 710c1d4 to 5e40f3f Compare November 24, 2025 15:11
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rustbot rustbot added T-clippy Relevant to the Clippy team. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Nov 24, 2025
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from 5e40f3f to d65444f Compare November 24, 2025 16:07
@jdonszelmann jdonszelmann force-pushed the exact-length-collection branch from d65444f to f201752 Compare November 24, 2025 16:14
@isuffix
Copy link

isuffix commented Nov 25, 2025

As you can see from the 2nd commit and the CI failures, since exactly_one conflicts with itertools we get some FCWs. How do we usually deal with those? I doubt this is the first iterator method that also already existed in itertools.

This should be resolved by supertrait item shadowing, which already has a stabilization PR 🎉. This was transitively mentioned in a comment by Amanieu on my older ACP for Chars::single (I've since changed accounts from @wrzian to @isuffix).

@jdonszelmann
Copy link
Contributor Author

yup, already talked to some peeps about it. Thanks!

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 26, 2025

📌 Commit f201752 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors 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 Nov 26, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
…on, r=Mark-Simulacrum

implement `Iterator::{exactly_one, collect_array}`

As per rust-lang#149266
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
…on, r=Mark-Simulacrum

implement `Iterator::{exactly_one, collect_array}`

As per rust-lang#149266
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
…on, r=Mark-Simulacrum

implement `Iterator::{exactly_one, collect_array}`

As per rust-lang#149266
bors added a commit that referenced this pull request Nov 26, 2025
Rollup of 19 pull requests

Successful merges:

 - #148048 (Stabilize `maybe_uninit_write_slice`)
 - #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls)
 - #148765 (std: split up the `thread` module)
 - #149074 (Add Command::get_env_clear)
 - #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers)
 - #149131 (optimize `slice::Iter::next_chunk`)
 - #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead))
 - #149239 (clarify float min/max behavios for NaNs and signed zeros)
 - #149243 (Fix typo and clarify bootstrap change tracker entry)
 - #149270 (implement `Iterator::{exactly_one, collect_array}`)
 - #149295 (Suggest _bytes versions of endian-converting methods)
 - #149301 (Motor OS: make decode_error_kind more comprehensive)
 - #149306 (bootstrap: Miri now handles jemalloc like everything else)
 - #149325 (rustdoc: add regression test for #140968)
 - #149332 (fix rustdoc search says “Consider searching for "null" instead.” #149324)
 - #149349 (Fix typo in comment.)
 - #149353 (Tidying up UI tests [3/N])
 - #149355 (Document that `build.description` affects symbol mangling and crate IDs)
 - #149360 (Enable CI download for windows-gnullvm)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 27, 2025
…on, r=Mark-Simulacrum

implement `Iterator::{exactly_one, collect_array}`

As per rust-lang#149266
bors added a commit that referenced this pull request Nov 27, 2025
Rollup of 8 pull requests

Successful merges:

 - #149238 (float::clamp: make treatment of signed zeros unspecified)
 - #149270 (implement `Iterator::{exactly_one, collect_array}`)
 - #149295 (Suggest _bytes versions of endian-converting methods)
 - #149332 (fix rustdoc search says “Consider searching for "null" instead.” #149324)
 - #149349 (Fix typo in comment.)
 - #149353 (Tidying up UI tests [3/N])
 - #149355 (Document that `build.description` affects symbol mangling and crate IDs)
 - #149360 (Enable CI download for windows-gnullvm)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3a62a46 into rust-lang:main Nov 27, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 27, 2025
rust-timer added a commit that referenced this pull request Nov 27, 2025
Rollup merge of #149270 - jdonszelmann:exact-length-collection, r=Mark-Simulacrum

implement `Iterator::{exactly_one, collect_array}`

As per #149266
@leonardo-m
Copy link

Implementing exactly_one in terms of collect_array seems to generate the exact same code as a dedicated implementation

In past I've tried to implement a collect_array using next_chunk or similar things from the std lib, and it wasn't efficent, so I had to restore my original custom implementation of collect_array. So before merging this into a nonnightly rustc, it's a good idea to benchmark it well, with arrays large at least 5000 items, or 2D arrays of 100x30 ints, etc, against a "native" version not based on next_chunk. If you really need something to do that benchmark, I can probably extract the code from my libs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants