about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2020-03-25impl TrustedRandomAccess for Fuse without FusedIteratorJosh Stone-2/+6
2020-03-24Implement Fuse with OptionJosh Stone-255/+340
The former `done` flag was roughly similar to an `Option` tag, but left the possibity of misuse. By using a real `Option`, we can set `None` when the iterator is exhausted, removing any way to call it again. We also allow niche layout this way, so the `Fuse` may be smaller. The `FusedIterator` specialization does want to ignore the possibility of exhaustion though, so it uses `unsafe { intrinsics::unreachable() }` to optimize that branch away. The entire `Fuse` implementation is now isolated in its own module to contain that unsafety.
2020-03-22Auto merge of #68820 - WaffleLapkin:remove_finished_from_map_while, ↵bors-57/+32
r=LukasKalbertodt Remove `finished` flag from `MapWhile` This PR removes `finished` flag from `MapWhile` as been proposed in https://github.com/rust-lang/rust/pull/66577#discussion_r370958025. This also resolves open questions of the tracking issue (#68537): - `MapWhile` can't implement both + `DoubleEndedIterator` (discussed in https://github.com/rust-lang/rust/pull/66577#discussion_r370947990 and following comments) + `FusedIterator` (this pr removes `finished` flag, so `MapWhile` isn't fused anymore) - Debug output (this pr removes `finished` flag, so there is no question in including it in debug output) r? @Mark-Simulacrum
2020-03-21slightly change the `Iterator::map_while` docsWaffle-14/+4
2020-03-18Auto merge of #68915 - timvermeulen:non_fused_iter, r=Amanieubors-9/+18
Fix bugs in Peekable and Flatten when using non-fused iterators I fixed a couple of bugs with regard to the `Peekable` and `Flatten`/`FlatMap` iterators when the underlying iterator isn't fused. For testing, I also added a `NonFused` iterator wrapper that panics when `next` or `next_back` is called on an iterator that has returned `None` before, which will hopefully make it easier to spot these mistakes in the future. ### Peekable `Peekable::next_back` was implemented as ```rust self.iter.next_back().or_else(|| self.peeked.take().and_then(|x| x)) ``` which is incorrect because when the `peeked` field is `Some(None)`, then `None` has already been returned from the inner iterator and what it returns from `next_back` can no longer be relied upon. `test_peekable_non_fused` tests this. ### Flatten When a `FlattenCompat` instance only has a `backiter` remaining (i.e. `self.frontiter` is `None` and `self.iter` is empty), then `next` will call `self.iter.next()` every time, so the `iter` field needs to be fused. I fixed it by giving it the type `Fuse<I>` instead of `I`, I think this is the only way to fix it. `test_flatten_non_fused_outer` tests this. Furthermore, previously `FlattenCompat::next` did not set `self.frontiter` to `None` after it returned `None`, which is incorrect when the inner iterator type isn't fused. I just delegated it to `try_fold` because that already handles it correctly. `test_flatten_non_fused_inner` tests this. r? @scottmcm
2020-03-17Fix FlattenCompat::{next, next_back}Tim Vermeulen-4/+6
2020-03-11Rollup merge of #69625 - Stebalien:feat/iter-copy-specialize, r=KodrAusMazdak Farrokhzad-0/+12
Implement nth, last, and count for iter::Copied Implement nth, last and count for iter::Copied.
2020-03-10Rollup merge of #69514 - GuillaumeGomez:remove-spotlight, r=kinnisonMazdak Farrokhzad-1/+0
Remove spotlight I had a few comments saying that this feature was at best misunderstood or not even used so I decided to organize a poll about on [twitter](https://twitter.com/imperioworld_/status/1232769353503956994). After 87 votes, the result is very clear: it's not useful. Considering the amount of code we have just to run it, I think it's definitely worth it to remove it. r? @kinnison cc @ollie27
2020-03-03Rollup merge of #69621 - matthiaskrgr:q, r=petrochenkovDylan DPC-6/+2
use question mark operator in a few places.
2020-03-03use question mark operator in a few places.Matthias Krüger-6/+2
2020-03-03Rollup merge of #69213 - LeSeulArtichaut:improve-doc-iter, r=steveklabnikYuki Okushi-2/+5
Improve documentation on iterators length Attempts to resolve #66491. @the8472 does this help? r? @steveklabnik
2020-03-02Apply suggestions from code reviewLeSeulArtichaut-2/+3
2020-03-01Implement nth, last, and count for iter::CopiedSteven Allen-0/+12
2020-02-27docs: note that find(f) is equivalent to filter(f).next() in the iterator docs.Matthias Krüger-0/+4
2020-02-27Remove spotlight usageGuillaume Gomez-1/+0
2020-02-24adjuste doc of `map_while`Waffle-10/+6
Fix doc of `Iterator::map_while` so it would be clearer that it isn't fused.
2020-02-18Rollup merge of #68597 - ollie27:skip_nth_last, r=AmanieuYuki Okushi-13/+7
Simplify `Skip::nth` and `Skip::last` implementations The main improvement is to make `last` no longer recursive.
2020-02-16Improve documentation on iteratorsLeSeulArtichaut-2/+4
2020-02-10Fuse FlattenCompat's inner iteratorTim Vermeulen-4/+7
2020-02-10Fix Peekable::next_backTim Vermeulen-1/+5
2020-02-08Remove problematic specialization from RangeInclusiveCAD97-22/+12
2020-02-08Auto merge of #68358 - matthewjasper:spec-fix, r=nikomatsakisbors-0/+4
Remove some unsound specializations This removes the unsound and exploitable specializations in the standard library * The `PartialEq` and `Hash` implementations for `RangeInclusive` are changed to avoid specialization. * The `PartialOrd` specialization for slices now specializes on a limited set of concrete types. * Added some tests for the soundness problems.
2020-02-04Remove `finished` flag from `MapWhile`Waffle-47/+36
2020-02-03Remove Copy impl from OnceWithOliver Middleton-1/+1
Iterators typically don't implement `Copy` and this shouldn't be an exception.
2020-02-04Stabilize `core::iter::once_with()`Yuki Okushi-12/+8
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).