Skip to content

Implement missing TrustedLen and FusedIterator for core and alloc types - #160838

Open
fereidani wants to merge 7 commits into
rust-lang:mainfrom
fereidani:trusted_and_fused_iter
Open

Implement missing TrustedLen and FusedIterator for core and alloc types#160838
fereidani wants to merge 7 commits into
rust-lang:mainfrom
fereidani:trusted_and_fused_iter

Conversation

@fereidani

@fereidani fereidani commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

While working on #160813 I noticed TrustedLen is missing for the LinkedList, I suspected that other modules are missing the implementation too, so I wrote a small script to scan the project and found these candidates which implement ExactSizeIterator but not the TrustedLen, Reviewed the code just to make sure they are actually meet TrustedLen requirement and then I've added missing implementations.

While editting I found out there are instances of FusedIterator missing too, So I've added them too.

I think most important missing one is the impl<I: TrustedLen + ?Sized, A: Allocator> TrustedLen for Box<I, A> which inherits TrustedLen for a Box to a TrustedLen implementer.

I did this only for core and alloc, I ignored script reports for the std but I think it worth looking into, specially for the HashMap:

FusedIterator::missing CommandArgs in library/std/src/process.rs
TrustedLen::missing CommandArgs in library/std/src/process.rs
FusedIterator::missing CommandEnvs in library/std/src/process.rs
TrustedLen::missing CommandEnvs in library/std/src/process.rs
FusedIterator::missing Args in library/std/src/env.rs
TrustedLen::missing Args in library/std/src/env.rs
FusedIterator::missing ArgsOs in library/std/src/env.rs
TrustedLen::missing ArgsOs in library/std/src/env.rs
TrustedLen::missing Iter in library/std/src/collections/hash/set.rs
TrustedLen::missing IntoIter in library/std/src/collections/hash/set.rs
TrustedLen::missing Drain in library/std/src/collections/hash/set.rs
TrustedLen::missing Iter in library/std/src/collections/hash/map.rs
TrustedLen::missing IterMut in library/std/src/collections/hash/map.rs
TrustedLen::missing IntoIter in library/std/src/collections/hash/map.rs
TrustedLen::missing Keys in library/std/src/collections/hash/map.rs
TrustedLen::missing Values in library/std/src/collections/hash/map.rs
TrustedLen::missing ValuesMut in library/std/src/collections/hash/map.rs
TrustedLen::missing IntoKeys in library/std/src/collections/hash/map.rs
TrustedLen::missing IntoValues in library/std/src/collections/hash/map.rs
TrustedLen::missing Drain in library/std/src/collections/hash/map.rs
FusedIterator::missing CommandArgs in library/std/src/sys/process/unsupported.rs
TrustedLen::missing CommandArgs in library/std/src/sys/process/unsupported.rs
FusedIterator::missing CommandArgs in library/std/src/sys/process/windows.rs
TrustedLen::missing CommandArgs in library/std/src/sys/process/windows.rs
FusedIterator::missing CommandArgs in library/std/src/sys/process/uefi.rs
TrustedLen::missing CommandArgs in library/std/src/sys/process/uefi.rs
FusedIterator::missing CommandArgs in library/std/src/sys/process/motor.rs
TrustedLen::missing CommandArgs in library/std/src/sys/process/motor.rs
FusedIterator::missing CommandEnvs in library/std/src/sys/process/env.rs
TrustedLen::missing CommandEnvs in library/std/src/sys/process/env.rs
FusedIterator::missing CommandArgs in library/std/src/sys/process/unix/common.rs
TrustedLen::missing CommandArgs in library/std/src/sys/process/unix/common.rs
FusedIterator::missing CStringIter in library/std/src/sys/process/unix/common/cstring_array.rs
TrustedLen::missing CStringIter in library/std/src/sys/process/unix/common/cstring_array.rs
FusedIterator::missing Args in library/std/src/sys/args/common.rs
TrustedLen::missing Args in library/std/src/sys/args/common.rs
FusedIterator::missing Args in library/std/src/sys/args/unsupported.rs
TrustedLen::missing Args in library/std/src/sys/args/unsupported.rs
FusedIterator::missing Args in library/std/src/sys/args/sgx.rs
TrustedLen::missing Args in library/std/src/sys/args/sgx.rs
FusedIterator::missing Args in library/std/src/sys/args/zkvm.rs
TrustedLen::missing Args in library/std/src/sys/args/zkvm.rs

This is related to #37572

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

@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 Aug 10, 2026
@rustbot

rustbot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

@Kobzol

Kobzol commented Aug 10, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
Implement missing TrustedLen and FusedIterator for core and alloc types
@rust-bors

rust-bors Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 9a3fc0e (9a3fc0e26f41ccaf3ebb3a1bcfa6e28817886e86)
Base parent: 8a2fbe3 (8a2fbe3ea881ec68b9f06510fd1a1484cdf5bb6b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9a3fc0e): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.1% [-6.9%, -0.4%] 27
All ❌✅ (primary) - - 0

Cycles

Results (secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.7% [0.5%, 1.2%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.8% [-1.3%, -0.4%] 9
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 454.914s -> 461.019s (1.34%)
Artifact size: 398.40 MiB -> 398.35 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants