about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2018-12-05Avoid calling clone in DoubleEndedIterator implementation of CopiedKonrad Borowski-2/+2
2018-12-05Use inner iterator may_have_side_effect for ClonedKonrad Borowski-1/+3
Previous implementation wasn't correct, as an inner iterator could have had side effects.
2018-12-05Copy may_have_side_effect from I for Copied<I>Konrad Borowski-1/+3
2018-12-05Use copied method instead of cloned in Copied::next_back()Konrad Borowski-1/+1
2018-12-05Add unstable Iterator::copied()Konrad Borowski-1/+128
2018-11-27Add missing doc linkGuillaume Gomez-1/+2
2018-11-26Add missing link in docsGuillaume Gomez-1/+1
2018-11-24Rollup merge of #55869 - SimonSapin:iterate, r=alexcrichtonkennytm-2/+165
Add std::iter::unfold This adds an **unstable** ~`std::iter::iterate`~ `std::iter::unfold` function and ~`std::iter::Iterate`~ `std::iter::Unfold` type that trivially wrap a ~`FnMut() -> Option<T>`~ `FnMut(&mut State) -> Option<T>` closure to create an iterator. ~Iterator state can be kept in the closure’s environment or captures.~ This is intended to help reduce amount of boilerplate needed when defining an iterator that is only created in one place. Compare the existing example of the `std::iter` module: (explanatory comments elided) ```rust struct Counter { count: usize, } impl Counter { fn new() -> Counter { Counter { count: 0 } } } impl Iterator for Counter { type Item = usize; fn next(&mut self) -> Option<usize> { self.count += 1; if self.count < 6 { Some(self.count) } else { None } } } ``` … with the same algorithm rewritten to use this new API: ```rust fn counter() -> impl Iterator<Item=usize> { std::iter::unfold(0, |count| { *count += 1; if *count < 6 { Some(*count) } else { None } }) } ``` ----- This also add unstable `std::iter::successors` which takes an (optional) initial item and a closure that takes an item and computes the next one (its successor). ```rust let powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10)); assert_eq!(powers_of_10.collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]); ```
2018-11-24Rollup merge of #55838 - dralley:fix-cfg-step, r=Kimundikennytm-4/+4
Fix #[cfg] for step impl on ranges ```#[cfg(target_pointer_witdth = ...)]``` is misspelled
2018-11-20fix more linksSteve Klabnik-3/+3
2018-11-20CapitalizeSimon Sapin-4/+4
2018-11-20Add tracking issue for unfold and successorsSimon Sapin-10/+10
2018-11-20Add std::iter::successorsSimon Sapin-1/+77
2018-11-20`Copy` is best avoided on iteratorsSimon Sapin-1/+1
2018-11-20Unfold<St, F>: Debug without F: DebugSimon Sapin-1/+10
2018-11-20Add std::iter::unfoldSimon Sapin-0/+78
2018-11-18revertАртём Павлов [Artyom Pavlov]-75/+7
2018-11-13Rollup merge of #55896 - rust-lang:opt-fuse, r=shepmasterkennytm-1/+1
Document optimizations enabled by FusedIterator When reading this I wondered what “some significant optimizations” referred to. As far as I can tell from reading code, the specialization of `.fuse()` is the only case where `FusedIterator` has any impact at all. Is this accurate @Stebalien?
2018-11-12Document optimizations enabled by FusedIteratorSimon Sapin-1/+1
When reading this I wondered what “some significant optimizations” referred to. As far as I can tell, the specialization of `.fuse()` is the only case where `FusedIterator` has any impact at all. Is this accurate @Stebalien?
2018-11-09Fix #[cfg] for step impl on rangesDaniel Alley-4/+4
2018-11-10revert making internal APIs const fn.Mazdak Farrokhzad-1/+1
2018-11-10constify parts of libcore.Mazdak Farrokhzad-2/+2
2018-10-26Remove unnecessary mut in iterator.find_map documentation example, Relates ↵Méven Car-1/+1
to #49098
2018-10-17Auto merge of #54946 - estebank:iterator, r=varkorbors-1/+62
Add filtering option to `rustc_on_unimplemented` and reword `Iterator` E0277 errors - Add more targetting filters for arrays to `rustc_on_unimplemented` (Fix #53766) - Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (Fix #23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (Fix #36391) - Suggest using range literal when iterating on integers (Fix #34353) - Do not suggest `.iter()` by default (Fix #50773, fix #46806) - Add regression test (Fix #22872)
2018-10-14Unused result warning: "X which must" ↦ "X that must"varkor-1/+1
2018-10-11Reword Range*/[Range*]: Iterator E0277 messagesEsteban Küber-6/+22
2018-10-11review commentsEsteban Küber-4/+28
- reword messages - apply custom comments to all types of ranges - fix indentation
2018-10-09fix tidyEsteban Küber-2/+4
2018-10-09Reword `rustc_on_unimplemented` errors for `Iterator`Esteban Küber-1/+20
- Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (#23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (#36391) - Suggest using range literal when iterating on integers (#34353) - Do not suggest `.iter()` by default (#50773, #46806)
2018-09-29Use impl_header_lifetime_elision in libcoreScott McMurray-4/+4
2018-08-30fix u32 steps_between for 16-bit systemsAndre Bogus-2/+10
2018-08-25Auto merge of #53385 - matklad:stabilize-find-map, r=KodrAusbors-4/+1
Stablize Iterator::find_map Stabilization PR for https://github.com/rust-lang/rust/issues/49602
2018-08-15Fix since of Iterator::flatten to be a proper semverAleksey Kladov-7/+7
2018-08-15Stablize Iterator::find_mapAleksey Kladov-4/+1
2018-08-04Remove redundant field names in structsljedrz-9/+9
2018-07-25Enforce #![deny(bare_trait_objects)] in src/libcoreljedrz-1/+1
2018-07-17Clarify short-circuiting behvaior of Iterator::zip.Corey Farwell-1/+3
Fixes https://github.com/rust-lang/rust/issues/52279.
2018-07-13Changed implementation of the third field to make LLVM optimize it better.kennytm-25/+25
2018-07-13Upgrade implementation of StepBy<RangeInclusive<_>>.kennytm-3/+5
2018-07-13Change RangeInclusive to a three-field struct.kennytm-70/+30
Fix #45222.
2018-07-10step_by: leave time of item skip unspecifiedEmerentius-1/+22
this gives us some leeway when optimizing
2018-07-03Auto merge of #51564 - SimonSapin:try-int, r=alexcrichtonbors-73/+2
Implement always-fallible TryFrom for usize/isize conversions that are infallible on some platforms This reverts commit 837d6c70233715a0ae8e15c703d40e3046a2f36a "Remove TryFrom impls that might become conditionally-infallible with a portability lint". This fixes #49415 by adding (restoring) missing `TryFrom` impls for integer conversions to or from `usize` or `isize`, by making them always fallible at the type system level (that is, with `Error=TryFromIntError`) even though they happen to be infallible on some platforms (for some values of `size_of::<usize>()`). They had been removed to allow the possibility to conditionally having some of them be infallible `From` impls instead, depending on the platforms, and have the [portability lint](https://github.com/rust-lang/rfcs/pull/1868) warn when they are used in code that is not already opting into non-portability. For example `#[allow(some_lint)] usize::from(x: u64)` would be valid on code that only targets 64-bit platforms. This PR gives up on this possiblity for two reasons: * Based on discussion with @aturon, it seems that the portability lint is not happening any time soon. It’s better to have the conversions be available *at all* than keep blocking them for so long. Portability-lint-gated platform-specific APIs can always be added separately later. * For code that is fine with fallibility, the alternative would force it to opt into "non-portability" even though there would be no real portability issue.
2018-07-01Rollup merge of #51511 - Centril:feature/stabilize_iterator_flatten, ↵Pietro Albini-13/+7
r=SimonSapin Stabilize Iterator::flatten in 1.29, fixes #48213. This PR stabilizes [`Iterator::flatten`](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.flatten) in *version 1.29* (1.28 goes to beta in 10 days, I don't think there's enough time to land it in that time, but let's see...). Tracking issue is: #48213. cc @bluss re. itertools. r? @SimonSapin ping @pietroalbini -- let's do a crater run when this passes CI :)
2018-06-22Auto merge of #51463 - estebank:error-codes, r=nikomatsakisbors-2/+5
Various changes to existing diagnostics * [Add code to `invalid ABI` error, add span label, move list to help to make message shorter](https://github.com/rust-lang/rust/pull/51463/commits/23ae5af274defa9ff884f593e44a2bbcaf814a02): ``` error[E0697]: invalid ABI: found `路濫狼á́́` --> $DIR/unicode.rs:11:8 | LL | extern "路濫狼á́́" fn foo() {} //~ ERROR invalid ABI | ^^^^^^^^^ invalid ABI | = help: valid ABIs: cdecl, stdcall, fastcall, vectorcall, thiscall, aapcs, win64, sysv64, ptx-kernel, msp430-interrupt, x86-interrupt, Rust, C, system, rust-intrinsic, rust-call, platform-intrinsic, unadjusted ``` * [Add code to incorrect `pub` restriction error](https://github.com/rust-lang/rust/pull/51463/commits/e96fdea8a38f39f99f8b9a4000a689187a457e08) * [Add message to `rustc_on_unimplemented` attributes in core to have them set a custom message _and_ label](https://github.com/rust-lang/rust/pull/51463/commits/2cc7e5ed307aee936c20479cfdc7409d6b52a464): ``` error[E0277]: `W` does not have a constant size known at compile-time --> $DIR/unsized-enum2.rs:33:8 | LL | VA(W), | ^ `W` does not have a constant size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `W` = help: consider adding a `where W: std::marker::Sized` bound = note: no field of an enum variant may have a dynamically sized type ``` ``` error[E0277]: `Foo` cannot be sent between threads safely --> $DIR/E0277-2.rs:26:5 | LL | is_send::<Foo>(); | ^^^^^^^^^^^^^^ `Foo` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `Foo` ``` ``` error[E0277]: can't compare `{integer}` with `std::string::String` --> $DIR/binops.rs:16:7 | LL | 5 < String::new(); | ^ no implementation for `{integer} < std::string::String` and `{integer} > std::string::String` | = help: the trait `std::cmp::PartialOrd<std::string::String>` is not implemented for `{integer}` ``` ``` error[E0277]: can't compare `{integer}` with `std::result::Result<{integer}, _>` --> $DIR/binops.rs:17:7 | LL | 6 == Ok(1); | ^^ no implementation for `{integer} == std::result::Result<{integer}, _>` | = help: the trait `std::cmp::PartialEq<std::result::Result<{integer}, _>>` is not implemented for `{integer}` ``` ``` error[E0277]: a collection of type `i32` cannot be built from an iterator over elements of type `i32` --> $DIR/type-check-defaults.rs:16:19 | LL | struct WellFormed<Z = Foo<i32, i32>>(Z); | ^ a collection of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` | = help: the trait `std::iter::FromIterator<i32>` is not implemented for `i32` note: required by `Foo` --> $DIR/type-check-defaults.rs:15:1 | LL | struct Foo<T, U: FromIterator<T>>(T, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` * [Add link to book for `Sized` errors](https://github.com/rust-lang/rust/pull/51463/commits/1244dc7c283323aea1a3457a4458d590a3e160c8): ``` error[E0277]: `std::fmt::Debug + std::marker::Sync + 'static` does not have a constant size known at compile-time --> $DIR/const-unsized.rs:13:29 | LL | const CONST_0: Debug+Sync = *(&0 as &(Debug+Sync)); | ^^^^^^^^^^^^^^^^^^^^^^ `std::fmt::Debug + std::marker::Sync + 'static` does not have a constant size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `std::fmt::Debug + std::marker::Sync + 'static` = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types--sized> = note: constant expressions must have a statically known size ``` * [Point to previous line for single expected token not found](https://github.com/rust-lang/rust/pull/51463/commits/48165168fb0f059d8536cd4a2276b609d4a7f721) (if the current token is in a different line)
2018-06-19Add message to `rustc_on_unimplemented` attributes in coreEsteban Küber-2/+5
2018-06-19specialize StepBy<Range(Inclusive)>Emerentius-7/+73
the originally generated code was highly suboptimal this brings it close to the same code or even exactly the same as a manual while-loop by eliminating a branch and the double stepping of n-1 + 1 steps The intermediate trait lets us circumvent the specialization type inference bugs
2018-06-13Replace `core::iter::AlwaysOk<T>` by `Result<T, !>`kennytm-19/+4
2018-06-11stabilize Iterator::flatten in 1.29, fixes #48115.Mazdak Farrokhzad-13/+7
2018-06-10Auto merge of #51200 - tmccombs:stable-iter-repeat-with, r=Centril,kennytmbors-20/+8
Stabilize iterator_repeat_with Fixes #48169
2018-06-06Revert "Remove TryFrom impls that might become conditionally-infallible with ↵Simon Sapin-73/+2
a portability lint" This reverts commit 837d6c70233715a0ae8e15c703d40e3046a2f36a. Fixes https://github.com/rust-lang/rust/issues/49415