Commit graph

436 commits

Author SHA1 Message Date
Mazdak Farrokhzad
fe998dbfe4
Rollup merge of #61457 - timvermeulen:double_ended_iters, r=scottmcm
Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take}

Now that `DoubleEndedIterator::nth_back` has landed, `StepBy` and `Take` can have an efficient `DoubleEndedIterator` implementation. I don't know if there was any particular reason for `Peekable` not having a `DoubleEndedIterator` implementation, but it's quite trivial and I don't see any drawbacks to having it.

I'm not very happy about the implementation of `Peekable::try_rfold`, but I didn't see another way to only take the value out of `self.peeked` in case `self.iter.try_rfold` didn't exit early.

I only added `Peekable::rfold` (in addition to `try_rfold`) because its `Iterator` implementation has both `fold` and `try_fold` (and for similar reasons I added `Take::try_rfold` but not `Take::rfold`). Do we have any guidelines on whether we want both? If we do want both, maybe we should investigate which iterator adaptors override `try_fold` but not `fold` and add the missing implementations. At the moment I think that it's better to always have iterator adaptors implement both, because some iterators have a simpler `fold` implementation than their `try_fold` implementation.

The tests that I added may not be sufficient because they're all just existing tests where `next`/`nth`/`fold`/`try_fold` are replaced by their DEI counterparts, but I do think all paths are covered. Is there anything in particular that I should probably also test?
2019-08-06 08:17:31 +02:00
Vadim Petrochenkov
434152157f Remove lint annotations in specific crates that are already enforced by rustbuild
Remove some random unnecessary lint `allow`s
2019-07-28 18:46:24 +03:00
Mazdak Farrokhzad
cb8b491a65
Rollup merge of #62074 - wizAmit:feature/mut_chunks_nth_back, r=scottmcm
squash of all commits for nth_back on ChunksMut

wip nth_back for chunks_mut

working chunksmut

fixed nth_back for chunksmut

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>

r? @timvermeulen
r? @scottmcm
2019-07-28 03:01:44 +02:00
Mazdak Farrokhzad
625aa60b3a
Rollup merge of #62421 - JohnTitor:U007D-master, r=alexcrichton
Introduce `as_deref` to Option

This is re-submission for #59628.
Renames `deref()` to `as_deref()` and adds `deref_mut()` impls and tests.

CC #50264

r? @Kimundi
(I picked you as you're the previous reviewer.)
2019-07-26 18:56:38 +02:00
Mazdak Farrokhzad
a57c4f6297
Rollup merge of #61884 - crlf0710:stablize_euc, r=dtolnay,Centril
Stablize Euclidean Modulo (feature euclidean_division)

Closes #49048
2019-07-25 23:20:53 +02:00
Brad Gibson
d1aca3aea5 renamed inner_deref feature's deref*() methods as_deref*() as per discussion https://github.com/rust-lang/rust/issues/50264 2019-07-18 15:17:30 +09:00
Tim Vermeulen
56ebfb185b Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take} 2019-07-09 23:38:57 +02:00
Josh Stone
265e3a6230 Unit test Iterator::partition_in_place and is_partitioned 2019-07-09 12:39:25 -07:00
Mazdak Farrokhzad
fb9ca03e0b
Rollup merge of #60458 - KodrAus:debug_map_entry, r=alexcrichton
Add key and value methods to DebugMap

Implementation PR for an active (not approved) RFC: https://github.com/rust-lang/rfcs/pull/2696.

Add two new methods to `std::fmt::DebugMap` for writing the key and value part of a map entry separately:

```rust
impl<'a, 'b: 'a> DebugMap<'a, 'b> {
    pub fn key(&mut self, key: &dyn Debug) -> &mut Self;
    pub fn value(&mut self, value: &dyn Debug) -> &mut Self;
}
```

I want to do this so that I can write a `serde::Serializer` that forwards to our format builders, so that any `T: Serialize` can also be treated like a `T: Debug`.
2019-07-09 04:52:35 +02:00
Ashley Mannix
e98ea52762 add key and value methods to DebugMap 2019-07-08 09:56:02 +10:00
CrLF0710
72ac8ce9aa Stablize Euclidean Modulo (feature euclidean_division) 2019-07-07 12:16:13 +08:00
Mazdak Farrokhzad
144ed029c5
Rollup merge of #62346 - RalfJung:miri-tests, r=Centril
enable a few more tests in Miri and update the comment for others
2019-07-04 01:39:02 +02:00
Ralf Jung
4dd5edc76d enable a few more tests in Miri and update the comment for others 2019-07-03 19:58:59 +02:00
Mark Rousskov
08e8c41904
Rollup merge of #62319 - ia0:fix_kleene, r=petrochenkov
Fix mismatching Kleene operators
2019-07-03 09:59:30 -04:00
Julien Cretin
dd702cc653 Fix mismatching Kleene operators 2019-07-03 00:37:25 +02:00
@amit.chandra
b95bde4491 squash of all commits for nth_back on ChunksMut
wip nth_back for chunks_mut

working chunksmut

fixed nth_back for chunksmut

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-06-23 12:45:59 +05:30
@amit.chandra
45832383af squash commit for nth_back on chunks exact
wip nth_back for chunks_exact

working nth_back for chunks exact

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-06-23 02:02:21 +05:30
Mazdak Farrokhzad
2e7e131b8e
Rollup merge of #60772 - timvermeulen:slice_iter_nth_back, r=scottmcm
Implement nth_back for slice::{Iter, IterMut}

Part of #54054.

I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂

I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.

I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
2019-06-20 08:36:00 +02:00
Mazdak Farrokhzad
3e08f1b57e
Rollup merge of #60454 - acrrd:issues/54054_skip, r=scottmcm
Add custom nth_back to Skip

Implementation of nth_back for Skip.
Part of #54054
2019-06-20 08:35:58 +02:00
Mazdak Farrokhzad
a1ff450a68
Rollup merge of #61398 - kennytm:stabilize-copy-within, r=SimonSapin
Stabilize copy_within

Closes #54236.
2019-06-13 01:49:26 +02:00
Mazdak Farrokhzad
3a8dc44f3c
Rollup merge of #61671 - koalatux:nth-back-range, r=KodrAus
implement nth_back for Range(Inclusive)

This is part of  #54054.
2019-06-12 04:22:51 +02:00
Adrian Friedli
8590074a01
implement nth_back for RangeInclusive 2019-06-09 22:45:11 +02:00
Ralf Jung
60d8675312 Miri: disable a slow test 2019-06-09 14:04:30 +02:00
Adrian Friedli
26d4c8f01c
implement nth_back for Range 2019-06-08 22:30:45 +02:00
Mazdak Farrokhzad
654854fdb5
Rollup merge of #61376 - czipperz:bound-cloned, r=sfackler
Add Bound::cloned()

Suggested by #61356
2019-06-06 22:39:09 +02:00
kennytm
427f1a49f6
Update src/libcore/tests/slice.rs
Co-Authored-By: Jack O'Connor <oconnor663@gmail.com>
2019-06-04 00:27:28 +08:00
kennytm
aac9bc5ffa
copy_within: replace element access by pointer arithmetic to avoid UB
This ensures we won't accidentally read *src or *dest even when count = 0.
2019-06-02 23:30:18 +08:00
Chris Gregory
c478efbe6a Enable feature bound_cloned for tests 2019-06-01 22:39:13 -07:00
Mazdak Farrokhzad
7d3a0dd2fb
Rollup merge of #61364 - lzutao:stabilize-reverse_bits, r=Centril
Stabilize reverse_bits feature

FCP done in https://github.com/rust-lang/rust/issues/48763#issuecomment-497349379

Closes #48763

r? @Centril
2019-06-01 06:50:03 +02:00
Chris Gregory
a21a0e0268 Import Bound in tests 2019-05-31 16:56:26 -05:00
Chris Gregory
df845784ee Add Bound tests 2019-05-31 11:36:37 -05:00
kennytm
be6fc6aca2
Stabilize copy_within 2019-05-31 20:02:07 +08:00
Lzu Tao
1c26bbf628 Stabilize reverse_bits feature 2019-05-31 04:43:53 +00:00
Lzu Tao
0c35c699d4 Stabilize iter_nth_back feature 2019-05-30 18:00:17 +00:00
Andrea Corradi
e80a37558d Add custom nth_back for Skip 2019-05-29 22:33:38 +02:00
Mazdak Farrokhzad
f0ea975a1c
Rollup merge of #61048 - wizAmit:feature/nth_back_chunks, r=scottmcm
Feature/nth back chunks

A succinct implementation for nth_back on chunks. Thank you @timvermeulen for the guidance.

r? @timvermeulen
2019-05-29 08:15:55 +02:00
Mazdak Farrokhzad
23b9b8320b
Rollup merge of #60555 - timvermeulen:rchunks_nth_back, r=scottmcm
Implement nth_back for RChunks(Exact)(Mut)

Part of #54054.

These implementations may not be optimal because of the use of `self.len()`, but it's quite cheap and simplifies the code a lot.

There's quite some duplication going on here, I wouldn't mind cleaning this up later. A good next step would probably be to add private `split_off_up_to`/`split_off_from` helper methods for slices since their behavior is commonly useful throughout the `Chunks` types.

r? @scottmcm
2019-05-29 08:15:51 +02:00
Mazdak Farrokhzad
d67d1f24dc
Rollup merge of #58975 - jtdowney:iter_arith_traits_option, r=dtolnay
Implement `iter::Sum` and `iter::Product` for `Option`

This is similar to the existing implementation for `Result`. It will take each item into the accumulator unless a `None` is returned.

I based a lot of this on #38580. From that discussion it didn't seem like this addition would be too controversial or difficult. One thing I still don't understand is picking the values for the `stable` attribute. This is my first non-documentation PR for rust so I am open to any feedback on improvements.
2019-05-29 08:15:48 +02:00
Tim Vermeulen
97a6c932e0 Implement nth_back for slice::{Iter, IterMut} 2019-05-25 01:47:24 +02:00
wizAmit
bcfd1f39e7 fix merge conflicts 2019-05-22 22:55:16 +05:30
wizAmit
9309447397 succint implementation 2019-05-22 22:27:30 +05:30
@amit.chandra
29a103daa9 wip nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-22 22:02:17 +05:30
@amit.chandra
2080b86566 hopefully working nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-22 21:58:57 +05:30
@amit.chandra
dc82626262 wip nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-22 21:58:57 +05:30
wizAmit
16223e4bea new implementation for nth_back for chunks 2019-05-14 13:28:43 +05:30
Richard Wiedenhöft
07e8d84479 Add const_unchecked_layout test to libcore/tests 2019-05-14 09:41:50 +02:00
@amit.chandra
aff83c80dd hopefully working nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-14 12:26:25 +05:30
@amit.chandra
02a148dba2 wip nth_back on chunks
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-14 12:26:25 +05:30
Mazdak Farrokhzad
c8ef512480
Rollup merge of #60201 - RalfJung:core-tests, r=alexcrichton
coretest: Downgrade deny to warn

The `deny` causes a build failure in https://github.com/RalfJung/miri-test-libstd. Since we use `-D warnings` for rustc builds, `warn` should be enough to lead to compile errors here, without impeding external builds.
2019-05-13 21:36:51 +02:00
Tim Vermeulen
5eb0e08d0f Implement nth_back for RChunks(Exact)(Mut) 2019-05-05 11:21:30 +02:00