about summary refs log tree commit diff
path: root/library/core/src/iter/traits
AgeCommit message (Collapse)AuthorLines
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-1/+1
2025-09-18Specialize `Iterator::eq[_by]` for `TrustedLen` iteratorsYotam Ofek-4/+48
2025-09-07Implement 'Sum' and 'Product' for 'f16' and 'f128';Gabriel Bjørnager Jensen-1/+1
2025-08-28implement Sum and Product for Saturating(u*)Jeremy Smart-1/+57
2025-08-07doc(library): Fix Markdown in `Iterator::by_ref`.Ivan Enderlin-1/+1
This patch fixes the Markdown formatting in `std::core::iter::Iterator::by_ref`. Code is used inside a link without the backticks around the code.
2025-07-25Add parentheses around expression arguments to `..`Josh Triplett-1/+1
This makes it easier for humans to parse, and improves the result of potential future automatic formatting.
2025-07-18clippy fix: bound in one placeMarijn Schouten-4/+4
2025-07-08collect.rs: remove empty line after doc commentMarijn Schouten-1/+0
2025-05-25Auto merge of #141086 - a1phyr:spec_advance_by, r=jhprattbors-5/+31
Implement `advance_by` via `try_fold` for `Sized` iterators When `try_fold` is overriden, it is usually easier for compilers to optimize. Example difference: https://iter.godbolt.org/z/z8cEfnKro
2025-05-17Switch library rustc_unimplemented to use `Self` and `This`mejrs-20/+17
2025-05-16Implement `advance_by` via `try_fold` for `Sized` iteratorsBenoît du Garreau-5/+31
When `try_fold` is overriden, it is usually easier for compilers to optimize.
2025-05-06Rollup merge of #136183 - hkBst:patch-25, r=AmanieuGuillaume Gomez-230/+225
Update iterator.rs to use arrays by value Update examples to no longer avoid iterating arrays for #84513
2025-05-06Update iterator.rs to use arrays by valueMarijn Schouten-230/+225
Update examples to no longer avoid iterating arrays for #84513
2025-05-02docs: alias `limit` to `Iterator::take`, cite `[u8]::utf8_chunks` in ↵Lieselotte-0/+1
`Utf8Chunks`
2025-04-13docs: Add example to `Iterator::take` with `by_ref`Diego Ongaro-0/+18
If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
2025-04-06doc changesizarma-5/+5
2025-03-30use `diagnostic::on_unimplemented` insteadmejrs-2/+2
2025-03-19use thenbendn-5/+1
2025-03-16Rollup merge of #138329 - scottmcm:assert-hint, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-0/+9
debug-assert that the size_hint is well-formed in `collect` Closes #137919 In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones #137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`. There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
2025-03-16Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc许杰友 Jieyou Xu (Joe)-6/+6
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-11Rollup merge of #135987 - hkBst:patch-20, r=joboetJakub Beránek-3/+15
Clarify iterator by_ref docs fixes #95143
2025-03-10debug-assert that the size_hint is well-formed in `collect`Scott McMurray-0/+9
2025-03-09Clarify iterator by_ref docsMarijn Schouten-3/+15
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-6/+6
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-02-08Document `Sum::sum` returns additive identities for `[]`Jaken Herman-1/+6
Because the neutral element of `<fNN as iter::Sum>` was changed to `neg_zero`, the documentation needed to be updated, as it was reporting inadequate information about what should be expected from the return. Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-01-08update version placeholdersPietro Albini-1/+1
2024-12-26Rollup merge of #134782 - wtlin1228:docs/iter-rposition, r=Mark-SimulacrumJacob Pratt-0/+1
Update Code Example for `Iterator::rposition` Added an additional assertion to the example to show the behavior of `iter.next_back` after using `iter.rposition`.
2024-12-26Impl FromIterator for tuples with arity 1-12Sebastian Hahn-33/+35
2024-12-26Fix formattingSebastian Hahn-19/+19
2024-12-26docs: update code example for Iterator#rpositionwtlin1228-0/+1
2024-12-21Less unwrap() in documentationKornel-3/+3
2024-12-14Correct spelling of CURRENT_RUSTC_VERSIONSebastian Hahn-7/+56
I mixed it up with RUSTC_CURRENT_VERSION unfortunately. Also improve the formatting of the macro invocation slightly.
2024-12-06Rollup merge of #132187 - shahn:extend_more_tuples, r=dtolnayMatthias Krüger-110/+129
Add Extend impls for tuples of arity 1 through 12
2024-11-28Also use zero when referencing to capacity or lengthtimvisee-2/+2
2024-10-31Don't impl Extend for 13-tuplesSebastian Hahn-1/+0
2024-10-30Remove do_not_const_check from Iterator methodsMichael Goulet-76/+0
2024-10-26Simplify documentation for Extend impl for tuplesSebastian Hahn-14/+6
2024-10-26Add Extend impls for tuples of arity 1 through 12Sebastian Hahn-110/+138
2024-10-25Re-do recursive const stability checksRalf Jung-1/+0
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-09Library: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-09-18[Clippy] Swap `manual_retain` to use diagnostic items instead of pathsGnomedDev-0/+3
2024-09-03replace placeholder versionBoxy-3/+3
2024-08-20Change neutral element of <fNN as iter::Sum> to neg_zeroArthur Carcano-2/+2
The neutral element used to be positive zero, but +0 + -0 = +0 so -0 seems better indicated.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-20/+13
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Rollup merge of #127765 - bitfield:fix_stdlib_doc_nits, r=dtolnayGuillaume Gomez-4/+4
Fix doc nits Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo"), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits.
2024-07-28stabilize `is_sorted`Slanterns-9/+3
2024-07-26Fix docsharryscholes-1/+1
2024-07-26Fix doc nitsJohn Arundel-4/+4
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-07Specialize `TrustedLen` for `Iterator::unzip()`Chayim Refael Friedman-15/+107
Don't check the capacity every time (and also for `Extend` for tuples, as this is how `unzip()` is implemented). I did this with an unsafe method on `Extend` that doesn't check for growth (`extend_one_unchecked()`). I've marked it as perma-unstable currently, although we may want to expose it in the future so collections outside of std can benefit from it. Then specialize `Extend for (A, B)` for `TrustedLen` to call it. It may seem that an alternative way of implementing this is to have a semi-public trait (`#[doc(hidden)]` public, so collections outside of core can implement it) for `extend()` inside tuples, and specialize it from collections. However, it is impossible due to limitations of `min_specialization`. A concern that may arise with the current approach is that implementing `extend_one_unchecked()` correctly must also incur implementing `extend_reserve()`, otherwise you can have UB. This is a somewhat non-local safety invariant. However, I believe this is fine, since to have actual UB you must have unsafe code inside your `extend_one_unchecked()` that makes incorrect assumption, *and* not implement `extend_reserve()`. I've also documented this requirement.