about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2020-02-01Remove some unsound specializationsMatthew Jasper-0/+4
2020-01-28Fill tracking issue for `iter_map_while` featureWaffle-5/+5
2020-01-28Add `Iterator::map_while` method and corresponding `MapWhile` adapterWaffle-1/+192
2020-01-28Simplify `Skip::nth` and `Skip::last` implementationsOliver Middleton-13/+7
The main improvement is to make `last` no longer recursive.
2020-01-22Avoid overflow in `std::iter::Skip::count`Oliver Middleton-2/+8
The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.
2020-01-18Make iter::Empty<T> implement Send and Sync for any TKonrad Borowski-0/+5
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-8/+2
2020-01-06Use Self instead of $typeLzu Tao-8/+8
2020-01-02Add Iterator::try_findMOZGIII-0/+37
2019-12-30Rollup merge of #67564 - Mark-Simulacrum:iter-adapter-panic, r=LukasKalbertodtYuki Okushi-0/+5
docs: Iterator adapters have unspecified results after a panic Fixes #58170. That issue also has rough consensus from 3 members of the library team for this being the behavior we would like to specify.
2019-12-24x.py fmt after previous deignoreMark Rousskov-412/+713
2019-12-23docs: Iterator adapters have unspecified results after a panicMark Rousskov-0/+5
2019-12-22Format the worldMark Rousskov-127/+171
2019-12-18Propagate cfg bootstrapMark Rousskov-9/+1
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-0/+1
functions with a `const` modifier
2019-12-06Format libcore with rustfmt (including tests and benches)David Tolnay-6/+6
2019-12-03Tweak wording of `collect()` on bad target typeEsteban Küber-2/+2
2019-11-26Format libcore with rustfmtDavid Tolnay-80/+143
This commit applies rustfmt with default settings to files in src/libcore *that are not involved in any currently open PR* to minimize merge conflicts. The list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in `outstanding_files`, the relevant commands were: $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018 $ rg libcore outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libcore.
2019-11-23Rollup merge of #66583 - Phlosioneer:patch-2, r=Dylan-DPCMazdak Farrokhzad-2/+6
Clarify Step Documentation While the redesign is in progress (#62886), clarify the purpose of replace_zero and replace_one. First, "returning itself" is technically impossible due to the function signature of &mut self -> Self. A clone or copy operation must be used. So this is now explicitly stated in the documentation. Second, the added docs give some guidance about the actual contract around implementation of replace_zero and replace one. Specifically, the only usage is to create a range with no more steps, by setting start to replace_one and end to replace_zero. So the only property that is actually used is `replace_one > replace_zero`. See https://github.com/rust-lang/rust/issues/42168#issuecomment-489554232 The new documentation does not say that is the *only* contract, and so it should not be considered an api change. It just highlights the most important detail for implementors. The redesign doesn't seem to be landing any time soon, so this is a stopgap measure to reduce confusion in the meantime.
2019-11-22follow the convention in this file to use third-person singular verbsGuanqun Lu-2/+2
2019-11-20Clarify Step DocumentationPhlosioneer-2/+6
While the redesign is in progress (#62886), clarify the purpose of replace_zero and replace_one.
2019-11-13Rollup merge of #66094 - ArturKovacs:fix-count-doc, r=Dylan-DPCYuki Okushi-3/+4
Fix documentation for `Iterator::count()`. The documentation of std::core::Iterator::count() stated that the number returned is the number of times `next` is called on the iterator. However this is not true as the number of times `next` is called is exactly one plus the number returned by `count()`.
2019-11-07Rollup merge of #63793 - oli-obk:🧹, r=dtolnayMazdak Farrokhzad-2/+14
Have tidy ensure that we document all `unsafe` blocks in libcore cc @rust-lang/libs I documented a few and added ignore flags on the other files. We can incrementally document the files, but won't regress any files this way.
2019-11-07Rollup merge of #66017 - LukasKalbertodt:array-into-iter-lint, r=matthewjasperMazdak Farrokhzad-0/+1
Add future incompatibility lint for `array.into_iter()` This is for #65819. This lint warns when calling `into_iter` on an array directly. That's because today the method call resolves to `<&[T] as IntoIterator>::into_iter` but that would change when adding `IntoIterator` impls for arrays. This problem is discussed in detail in #65819. We still haven't decided how to proceed exactly, but it seems like adding a lint is a good idea regardless? Also: this is the first time I implement a lint, so there are probably a lot of things I can improve. I used a different strategy than @scottmcm describes [here](https://github.com/rust-lang/rust/pull/65819#issuecomment-548667847) since I already started implementing this before they commented. ### TODO - [x] Decide if we want this lint -> apparently [we want](https://github.com/rust-lang/rust/pull/65819#issuecomment-548964818) - [x] Open a lint-tracking-issue and add the correct issue number in the code -> https://github.com/rust-lang/rust/issues/66145
2019-11-06Add future incompatibility lint for `array.into_iter()`Lukas Kalbertodt-0/+1
As we might want to add `IntoIterator` impls for arrays in the future, and since that introduces a breaking change, this lint warns and suggests using `iter()` instead (which is shorter and more explicit).
2019-11-06Halloween... time to get rid of 👻Oliver Scherer-7/+11
2019-11-06Have tidy ensure that we document all `unsafe` blocks in libcoreOliver Scherer-0/+8
2019-11-05Rollup merge of #66019 - olegnn:fixed_std_iter_chain_docs, r=Mark-SimulacrumPietro Albini-1/+1
Improved std::iter::Chain documentation Replaces `strings two iterators` by `links two iterators` in `std::iter::Chain` documentation. I didn't find any meaning of `strings` which can be evaluated as `links` or `joins`. I don't think that `std::iter:Chain` works as a stringer or plays billiards. (https://www.lexico.com/en/definition/string).
2019-11-04Improve wording in the documentation of `Iterator::count()`.Artur Kovacs-4/+4
2019-11-04Fixed trailing whitespace.Artur Kovacs-1/+1
2019-11-04Fix documentation for `Iterator::count()`.Artur Kovacs-2/+3
2019-11-01Fixed std::iter::Chain documentationOleg Nosov-1/+1
2019-10-30doc: reword iter module example and mention other methodsLzu Tao-21/+14
2019-10-28doc: introduce `once` in `iter::chain` documentLzu Tao-3/+18
2019-10-20Remove leading :: from paths in doc examplesMikko Rantanen-1/+1
2019-10-01replace try_for_each with try_fold to generate less codeAndreas Jonson-13/+14
removes two functions to inline by combining the check functions and extra call to try_for_each
2019-09-24Rollup merge of #64296 - KodrAus:chore/iter_order_by, r=CentrilMazdak Farrokhzad-3/+3
Document the unstable iter_order_by library feature Tracking issue: #64295 Follow-up for: #62205 References the tracking issue and adds a page to the unstable book for the new unstable `iter_order_by` feature.
2019-09-21Auto merge of #64047 - timvermeulen:cmp_min_max_by, r=cuviperbors-31/+17
Add `cmp::{min_by, min_by_key, max_by, max_by_key}` This adds the following functions to `core::cmp`: - `min_by` - `min_by_key` - `max_by` - `max_by_key` `min_by` and `max_by` are somewhat trivial to implement, but not entirely because `min_by` returns the first value in case the two are equal (and `max_by` the second). `min` and `max` can be implemented in terms of `min_by` and `max_by`, but not as easily the other way around. To give an example of why I think these functions could be useful: the `Iterator::{min_by, min_by_key, max_by, max_by_key}` methods all currently hard-code the behavior mentioned above which is an ever so small duplication of logic. If we delegate them to `cmp::{min_by, max_by}` methods instead, we get the correct behavior for free. (edit: this is now included in the PR) I added `min_by_key` / `max_by_key` for consistency's sake but I wouldn't mind removing them. I don't have a particular use case in mind for them, and `min_by` / `max_by` seem to be more useful. Tracking issue: #64460
2019-09-14Simplify Iterator::{min_by, max_by} using cmp::{min_by, max_by}Tim Vermeulen-31/+17
2019-09-09Rollup merge of #64121 - timvermeulen:iter_step_by_internal, r=scottmcmMazdak Farrokhzad-1/+43
Override `StepBy::{try_fold, try_rfold}` Previous PR: https://github.com/rust-lang/rust/pull/51435 The previous PR was closed in favor of https://github.com/rust-lang/rust/pull/51601, which was later reverted. I don't think these implementations will make it harder to specialize `StepBy<Range<_>>` later, so we should be able to land this without any consequences. This should fix https://github.com/rust-lang/rust/issues/57517 – in my benchmarks `iter` and `iter.step_by(1)` now perform equally well, provided internal iteration is used.
2019-09-09document the unstable iter_order_by library featureAshley Mannix-3/+3
2019-09-06Add Iterator comparison methods that take a comparison functionTim Vermeulen-6/+103
2019-09-06Rollup merge of #64174 - GuillaumeGomez:missing-iterator-examples, r=sfacklerMazdak Farrokhzad-0/+80
Add missing code examples on Iterator trait Fixes #63865 cc @rust-lang/docs
2019-09-05Add missing code examples on Iterator traitGuillaume Gomez-0/+80
2019-09-04Override `StepBy::{try_fold, try_rfold}`Tim Vermeulen-1/+43
2019-08-30Rev::rposition counts from the wrong endXiang Fan-7/+0
Because of a compiler bug that adding `Self: ExactSizeIterator` makes the compiler forget `Self::Item` is `<I as Iterator>::Item`, we remove this specialization for now.
2019-08-22Apply clippy::needless_return suggestionsMateusz Mikuła-2/+2
2019-08-18Fix bug in iter::Chain::size_hintTim Vermeulen-8/+14
2019-08-17Rollup merge of #62737 - timvermeulen:cycle_try_fold, r=scottmcmMazdak Farrokhzad-0/+30
Override Cycle::try_fold It's not very pretty, but I believe this is the simplest way to correctly implement `Cycle::try_fold`. The following may seem correct: ```rust loop { acc = self.iter.try_fold(acc, &mut f)?; self.iter = self.orig.clone(); } ``` ...but this loops infinitely in case `self.orig` is empty, as opposed to returning `acc`. So we first have to fully iterate `self.orig` to check whether it is empty or not, and before _that_, we have to iterate the remaining elements of `self.iter`. This should always call `self.orig.clone()` the same amount of times as repeated `next()` calls would. r? @scottmcm
2019-08-16Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapinMazdak Farrokhzad-0/+23
Add custom nth_back for Chain Implementation of nth_back for Chain. Part of #54054