mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #42310 - scottmcm:deprecate-range-stepby, r=alexcrichton
Deprecate range-specific `step_by` Deprecation attributes and test updates only. Was replaced by an any-iterator version in https://github.com/rust-lang/rust/pull/41439 Last follow-up (this release) to https://github.com/rust-lang/rust/pull/42110#issuecomment-303210138 r? @alexcrichton
This commit is contained in:
commit
1316281f2d
@ -16,12 +16,12 @@
|
||||
#![feature(collections)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(exact_size_is_empty)]
|
||||
#![feature(iterator_step_by)]
|
||||
#![feature(pattern)]
|
||||
#![feature(placement_in_syntax)]
|
||||
#![feature(rand)]
|
||||
#![feature(slice_rotate)]
|
||||
#![feature(splice)]
|
||||
#![feature(step_by)]
|
||||
#![feature(str_escape)]
|
||||
#![feature(test)]
|
||||
#![feature(unboxed_closures)]
|
||||
|
@ -510,7 +510,8 @@ fn test_from_iter() {
|
||||
let u: Vec<_> = deq.iter().cloned().collect();
|
||||
assert_eq!(u, v);
|
||||
|
||||
let seq = (0..).step_by(2).take(256);
|
||||
// FIXME #27741: Remove `.skip(0)` when Range::step_by is fully removed
|
||||
let seq = (0..).skip(0).step_by(2).take(256);
|
||||
let deq: VecDeque<_> = seq.collect();
|
||||
for (i, &x) in deq.iter().enumerate() {
|
||||
assert_eq!(2 * i, x);
|
||||
|
@ -313,6 +313,9 @@ pub use self::iterator::Iterator;
|
||||
pub use self::range::Step;
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[rustc_deprecated(since = "1.19.0",
|
||||
reason = "replaced by `iter::StepBy`")]
|
||||
#[allow(deprecated)]
|
||||
pub use self::range::StepBy as DeprecatedStepBy;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -252,6 +252,9 @@ step_impl_no_between!(u128 i128);
|
||||
#[derive(Clone, Debug)]
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[rustc_deprecated(since = "1.19.0",
|
||||
reason = "replaced by `iter::StepBy`")]
|
||||
#[allow(deprecated)]
|
||||
pub struct StepBy<A, R> {
|
||||
step_by: A,
|
||||
range: R,
|
||||
@ -272,6 +275,9 @@ impl<A: Step> ops::RangeFrom<A> {
|
||||
/// ```
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[rustc_deprecated(since = "1.19.0",
|
||||
reason = "replaced by `Iterator::step_by`")]
|
||||
#[allow(deprecated)]
|
||||
pub fn step_by(self, by: A) -> StepBy<A, Self> {
|
||||
StepBy {
|
||||
step_by: by,
|
||||
@ -297,6 +303,9 @@ impl<A: Step> ops::Range<A> {
|
||||
/// ```
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[rustc_deprecated(since = "1.19.0",
|
||||
reason = "replaced by `Iterator::step_by`")]
|
||||
#[allow(deprecated)]
|
||||
pub fn step_by(self, by: A) -> StepBy<A, Self> {
|
||||
StepBy {
|
||||
step_by: by,
|
||||
@ -321,6 +330,9 @@ impl<A: Step> ops::RangeInclusive<A> {
|
||||
/// ```
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[rustc_deprecated(since = "1.19.0",
|
||||
reason = "replaced by `Iterator::step_by`")]
|
||||
#[allow(deprecated)]
|
||||
pub fn step_by(self, by: A) -> StepBy<A, Self> {
|
||||
StepBy {
|
||||
step_by: by,
|
||||
@ -331,6 +343,7 @@ impl<A: Step> ops::RangeInclusive<A> {
|
||||
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[allow(deprecated)]
|
||||
impl<A> Iterator for StepBy<A, ops::RangeFrom<A>> where
|
||||
A: Clone,
|
||||
for<'a> &'a A: Add<&'a A, Output = A>
|
||||
@ -351,11 +364,13 @@ impl<A> Iterator for StepBy<A, ops::RangeFrom<A>> where
|
||||
}
|
||||
|
||||
#[unstable(feature = "fused", issue = "35602")]
|
||||
#[allow(deprecated)]
|
||||
impl<A> FusedIterator for StepBy<A, ops::RangeFrom<A>>
|
||||
where A: Clone, for<'a> &'a A: Add<&'a A, Output = A> {}
|
||||
|
||||
#[unstable(feature = "step_by", reason = "recent addition",
|
||||
issue = "27741")]
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + Clone> Iterator for StepBy<A, ops::Range<A>> {
|
||||
type Item = A;
|
||||
|
||||
@ -393,11 +408,13 @@ impl<A: Step + Clone> Iterator for StepBy<A, ops::Range<A>> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "fused", issue = "35602")]
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + Clone> FusedIterator for StepBy<A, ops::Range<A>> {}
|
||||
|
||||
#[unstable(feature = "inclusive_range",
|
||||
reason = "recently added, follows RFC",
|
||||
issue = "28237")]
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + Clone> Iterator for StepBy<A, ops::RangeInclusive<A>> {
|
||||
type Item = A;
|
||||
|
||||
@ -437,6 +454,7 @@ impl<A: Step + Clone> Iterator for StepBy<A, ops::RangeInclusive<A>> {
|
||||
}
|
||||
|
||||
#[unstable(feature = "fused", issue = "35602")]
|
||||
#[allow(deprecated)]
|
||||
impl<A: Step + Clone> FusedIterator for StepBy<A, ops::RangeInclusive<A>> {}
|
||||
|
||||
macro_rules! range_exact_iter_impl {
|
||||
|
@ -12,6 +12,15 @@ use core::iter::*;
|
||||
use core::{i8, i16, isize};
|
||||
use core::usize;
|
||||
|
||||
// FIXME #27741: This is here to simplify calling Iterator::step_by. Remove
|
||||
// once Range::step_by is completely gone (not just deprecated).
|
||||
trait IterEx: Sized {
|
||||
fn iter_step_by(self, n: usize) -> StepBy<Self>;
|
||||
}
|
||||
impl<I:Iterator> IterEx for I {
|
||||
fn iter_step_by(self, n: usize) -> StepBy<Self> { self.step_by(n) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lt() {
|
||||
let empty: [isize; 0] = [];
|
||||
@ -67,7 +76,7 @@ fn test_multi_iter() {
|
||||
|
||||
#[test]
|
||||
fn test_counter_from_iter() {
|
||||
let it = (0..).step_by(5).take(10);
|
||||
let it = (0..).iter_step_by(5).take(10);
|
||||
let xs: Vec<isize> = FromIterator::from_iter(it);
|
||||
assert_eq!(xs, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
|
||||
}
|
||||
@ -85,7 +94,7 @@ fn test_iterator_chain() {
|
||||
}
|
||||
assert_eq!(i, expected.len());
|
||||
|
||||
let ys = (30..).step_by(10).take(4);
|
||||
let ys = (30..).iter_step_by(10).take(4);
|
||||
let it = xs.iter().cloned().chain(ys);
|
||||
let mut i = 0;
|
||||
for x in it {
|
||||
@ -147,15 +156,13 @@ fn test_iterator_chain_find() {
|
||||
#[test]
|
||||
fn test_iterator_step_by() {
|
||||
// Identity
|
||||
// Replace with (0..).step_by(1) after Range::step_by gets removed
|
||||
let mut it = Iterator::step_by((0..), 1).take(3);
|
||||
let mut it = (0..).iter_step_by(1).take(3);
|
||||
assert_eq!(it.next(), Some(0));
|
||||
assert_eq!(it.next(), Some(1));
|
||||
assert_eq!(it.next(), Some(2));
|
||||
assert_eq!(it.next(), None);
|
||||
|
||||
// Replace with (0..).step_by(3) after Range::step_by gets removed
|
||||
let mut it = Iterator::step_by((0..), 3).take(4);
|
||||
let mut it = (0..).iter_step_by(3).take(4);
|
||||
assert_eq!(it.next(), Some(0));
|
||||
assert_eq!(it.next(), Some(3));
|
||||
assert_eq!(it.next(), Some(6));
|
||||
@ -166,8 +173,7 @@ fn test_iterator_step_by() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_iterator_step_by_zero() {
|
||||
// Replace with (0..).step_by(0) after Range::step_by gets removed
|
||||
let mut it = Iterator::step_by((0..), 0);
|
||||
let mut it = (0..).iter_step_by(0);
|
||||
it.next();
|
||||
}
|
||||
|
||||
@ -246,7 +252,7 @@ fn test_iterator_step_by_size_hint() {
|
||||
|
||||
#[test]
|
||||
fn test_filter_map() {
|
||||
let it = (0..).step_by(1).take(10)
|
||||
let it = (0..).iter_step_by(1).take(10)
|
||||
.filter_map(|x| if x % 2 == 0 { Some(x*x) } else { None });
|
||||
assert_eq!(it.collect::<Vec<usize>>(), [0*0, 2*2, 4*4, 6*6, 8*8]);
|
||||
}
|
||||
@ -648,7 +654,7 @@ fn test_iterator_scan() {
|
||||
fn test_iterator_flat_map() {
|
||||
let xs = [0, 3, 6];
|
||||
let ys = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
let it = xs.iter().flat_map(|&x| (x..).step_by(1).take(3));
|
||||
let it = xs.iter().flat_map(|&x| (x..).iter_step_by(1).take(3));
|
||||
let mut i = 0;
|
||||
for x in it {
|
||||
assert_eq!(x, ys[i]);
|
||||
@ -674,13 +680,13 @@ fn test_inspect() {
|
||||
#[test]
|
||||
fn test_cycle() {
|
||||
let cycle_len = 3;
|
||||
let it = (0..).step_by(1).take(cycle_len).cycle();
|
||||
let it = (0..).iter_step_by(1).take(cycle_len).cycle();
|
||||
assert_eq!(it.size_hint(), (usize::MAX, None));
|
||||
for (i, x) in it.take(100).enumerate() {
|
||||
assert_eq!(i % cycle_len, x);
|
||||
}
|
||||
|
||||
let mut it = (0..).step_by(1).take(0).cycle();
|
||||
let mut it = (0..).iter_step_by(1).take(0).cycle();
|
||||
assert_eq!(it.size_hint(), (0, Some(0)));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
@ -759,7 +765,7 @@ fn test_iterator_min() {
|
||||
|
||||
#[test]
|
||||
fn test_iterator_size_hint() {
|
||||
let c = (0..).step_by(1);
|
||||
let c = (0..).iter_step_by(1);
|
||||
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
let v2 = &[10, 11, 12];
|
||||
let vi = v.iter();
|
||||
@ -1081,6 +1087,8 @@ fn test_range() {
|
||||
|
||||
#[test]
|
||||
fn test_range_step() {
|
||||
#![allow(deprecated)]
|
||||
|
||||
assert_eq!((0..20).step_by(5).collect::<Vec<isize>>(), [0, 5, 10, 15]);
|
||||
assert_eq!((20..0).step_by(-5).collect::<Vec<isize>>(), [20, 15, 10, 5]);
|
||||
assert_eq!((20..0).step_by(-6).collect::<Vec<isize>>(), [20, 14, 8, 2]);
|
||||
|
Loading…
Reference in New Issue
Block a user