about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2020-04-25Bump rustfmt to most recently shippedMark Rousskov-1/+1
2020-04-24Rollup merge of #71492 - LeSeulArtichaut:document-unsafe-2, r=Mark-SimulacrumDylan DPC-2/+8
Document unsafety in core::{panicking, alloc::layout, hint, iter::adapters::zip} Helps with #66219. r? @Mark-Simulacrum do you want to continue reading safety comments? :D
2020-04-24Document unsafety in `core::{panicking, alloc::layout, hint, ↵LeSeulArtichaut-2/+8
iter::adapters::zip}`
2020-04-23Rollup merge of #71404 - cuviper:chain-unfused, r=scottmcmDylan DPC-10/+22
Don't fuse Chain in its second iterator Only the "first" iterator is actually set `None` when exhausted, depending on whether you iterate forward or backward. This restores behavior similar to the former `ChainState`, where it would transition from `Both` to `Front`/`Back` and only continue from that side. However, if you mix directions, then this may still set both sides to `None`, totally fusing the iterator. Fixes #71375 r? @scottmcm
2020-04-21Don't fuse Chain in its second iteratorJosh Stone-10/+22
Only the "first" iterator is actually set `None` when exhausted, depending on whether you iterate forward or backward. This restores behavior similar to the former `ChainState`, where it would transition from `Both` to `Front`/`Back` and only continue from that side. However, if you mix directions, then this may still set both sides to `None`, totally fusing the iterator.
2020-04-20Stop accessing module level int consts via crate::<Ty>Linus Färnstrand-3/+0
2020-04-17Rollup merge of #71220 - cuviper:std_or_patterns, r=Mark-SimulacrumDylan DPC-2/+2
Dogfood or_patterns in the standard library We can start using `or_patterns` in the standard library as a step toward stabilization. cc #54883 @Centril
2020-04-17Rollup merge of #70910 - rakshith-ravi:master, r=cuviperDylan DPC-63/+244
Hides default fns inside Fuse impl to avoid exposing it to any crate Fixes #70796 @cuviper I've added some default, private traits to do the job for us. If required, I can expose them to a specific visibility if you want to call these functions for #70332 r? @cuviper
2020-04-16Dogfood or_patterns in the standard libraryJosh Stone-2/+2
2020-04-16Inlined everything into a single trait and trait implRakshith Ravi-126/+141
2020-04-10Added comments.Rakshith Ravi-21/+16
Removed unnecessarry empty impls. Moved code to organise it better
2020-04-08Added FuseIteratorImpl, FustDoubleEndedIteratorImpl and ↵Rakshith Ravi-79/+250
FuseExactSizeIteratorImpl to avoid exposing default functions outside of the current crate.
2020-04-07Avoid extra &mut in Chain::fold and try_foldJosh Stone-2/+2
2020-04-07Reduce callsites in Chain::last()Josh Stone-11/+10
2020-04-07Reduce callsites in Chain::count()Josh Stone-6/+9
2020-04-07Implement Chain with Option fusesJosh Stone-149/+106
The iterators are now "fused" with `Option` so we don't need separate state to track which part is already exhausted, and we may also get niche layout for `None`. We don't use the real `Fuse` adapter because its specialization for `FusedIterator` unconditionally descends into the iterator, and that could be expensive to keep revisiting stuff like nested chains. It also hurts compiler performance to add more iterator layers to `Chain`.
2020-04-06Rollup merge of #70750 - cuviper:direct-fuse, r=scottmcmMazdak Farrokhzad-74/+63
Match options directly in the Fuse implementation Rather than using `as_ref()`, `as_mut()`, and `?`, we can use `match` directly to save a lot of generated code. This was mentioned as a possibility in https://github.com/rust-lang/rust/pull/70366#issuecomment-603462546, and I found that it had a very large impact on #70332 using `Fuse` within `Chain`. Let's evaluate this change on its own first.
2020-04-03Use a macro to expand the specialized FuseJosh Stone-41/+23
2020-04-03Open-code Fuse's Option matchesJosh Stone-35/+42
2020-04-03Replace float module consts with assoc consts in documentationLinus Färnstrand-3/+3
2020-04-03Replace max/min_value() with MAX/MIN assoc constsLinus Färnstrand-1/+1
2020-03-27remove unused importdylan_DPC-1/+0
2020-03-27simplify testdylan_DPC-4/+1
2020-03-26fix docsdylan_DPC-2/+5
2020-03-26Add fold_selfNathan West-16/+40
- Added `Iterator::fold_first`, which is like `fold`, but uses the first element in the iterator as the initial accumulator - Includes doc and doctest - Rebase commit; see #65222 for details Co-Authored-By: Tim Vermeulen <tvermeulen@me.com>
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