Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod legacy;

use Bound::{Excluded, Included, Unbounded};
#[doc(inline)]
pub use iter::{IterRange, IterRangeFrom, IterRangeInclusive};
pub use iter::{RangeFromIter, RangeInclusiveIter, RangeIter};

#[doc(inline)]
pub use crate::iter::Step;
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<Idx: Step> Range<Idx> {
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[inline]
pub fn iter(&self) -> IterRange<Idx> {
pub fn iter(&self) -> RangeIter<Idx> {
self.clone().into_iter()
}
}
Expand Down Expand Up @@ -340,7 +340,7 @@ impl<Idx: Step> RangeInclusive<Idx> {
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[inline]
pub fn iter(&self) -> IterRangeInclusive<Idx> {
pub fn iter(&self) -> RangeInclusiveIter<Idx> {
self.clone().into_iter()
}
}
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<Idx: Step> RangeFrom<Idx> {
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[inline]
pub fn iter(&self) -> IterRangeFrom<Idx> {
pub fn iter(&self) -> RangeFromIter<Idx> {
self.clone().into_iter()
}
}
Expand Down
54 changes: 27 additions & 27 deletions library/core/src/range/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{intrinsics, mem};
/// By-value [`Range`] iterator.
#[unstable(feature = "new_range_api", issue = "125687")]
#[derive(Debug, Clone)]
pub struct IterRange<A>(legacy::Range<A>);
pub struct RangeIter<A>(legacy::Range<A>);

impl<A> IterRange<A> {
impl<A> RangeIter<A> {
/// Returns the remainder of the range being iterated over.
pub fn remainder(self) -> Range<A> {
Range { start: self.0.start, end: self.0.end }
Expand All @@ -23,11 +23,11 @@ macro_rules! unsafe_range_trusted_random_access_impl {
($($t:ty)*) => ($(
#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
unsafe impl TrustedRandomAccess for IterRange<$t> {}
unsafe impl TrustedRandomAccess for RangeIter<$t> {}

#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
unsafe impl TrustedRandomAccessNoCoerce for IterRange<$t> {
unsafe impl TrustedRandomAccessNoCoerce for RangeIter<$t> {
const MAY_HAVE_SIDE_EFFECT: bool = false;
}
)*)
Expand All @@ -50,7 +50,7 @@ unsafe_range_trusted_random_access_impl! {
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> Iterator for IterRange<A> {
impl<A: Step> Iterator for RangeIter<A> {
type Item = A;

#[inline]
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<A: Step> Iterator for IterRange<A> {
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> DoubleEndedIterator for IterRange<A> {
impl<A: Step> DoubleEndedIterator for RangeIter<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
self.0.next_back()
Expand All @@ -136,27 +136,27 @@ impl<A: Step> DoubleEndedIterator for IterRange<A> {
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<A: TrustedStep> TrustedLen for IterRange<A> {}
unsafe impl<A: TrustedStep> TrustedLen for RangeIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> FusedIterator for IterRange<A> {}
impl<A: Step> FusedIterator for RangeIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> IntoIterator for Range<A> {
type Item = A;
type IntoIter = IterRange<A>;
type IntoIter = RangeIter<A>;

fn into_iter(self) -> Self::IntoIter {
IterRange(self.into())
RangeIter(self.into())
}
}

/// By-value [`RangeInclusive`] iterator.
#[unstable(feature = "new_range_api", issue = "125687")]
#[derive(Debug, Clone)]
pub struct IterRangeInclusive<A>(legacy::RangeInclusive<A>);
pub struct RangeInclusiveIter<A>(legacy::RangeInclusive<A>);

impl<A: Step> IterRangeInclusive<A> {
impl<A: Step> RangeInclusiveIter<A> {
/// Returns the remainder of the range being iterated over.
///
/// If the iterator is exhausted or empty, returns `None`.
Expand All @@ -170,7 +170,7 @@ impl<A: Step> IterRangeInclusive<A> {
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> Iterator for IterRangeInclusive<A> {
impl<A: Step> Iterator for RangeInclusiveIter<A> {
type Item = A;

#[inline]
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<A: Step> Iterator for IterRangeInclusive<A> {
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> DoubleEndedIterator for IterRangeInclusive<A> {
impl<A: Step> DoubleEndedIterator for RangeInclusiveIter<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
self.0.next_back()
Expand All @@ -244,18 +244,18 @@ impl<A: Step> DoubleEndedIterator for IterRangeInclusive<A> {
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<A: TrustedStep> TrustedLen for IterRangeInclusive<A> {}
unsafe impl<A: TrustedStep> TrustedLen for RangeInclusiveIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> FusedIterator for IterRangeInclusive<A> {}
impl<A: Step> FusedIterator for RangeInclusiveIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> IntoIterator for RangeInclusive<A> {
type Item = A;
type IntoIter = IterRangeInclusive<A>;
type IntoIter = RangeInclusiveIter<A>;

fn into_iter(self) -> Self::IntoIter {
IterRangeInclusive(self.into())
RangeInclusiveIter(self.into())
}
}

Expand All @@ -270,14 +270,14 @@ impl<A: Step> IntoIterator for RangeInclusive<A> {
macro_rules! range_exact_iter_impl {
($($t:ty)*) => ($(
#[unstable(feature = "new_range_api", issue = "125687")]
impl ExactSizeIterator for IterRange<$t> { }
impl ExactSizeIterator for RangeIter<$t> { }
)*)
}

macro_rules! range_incl_exact_iter_impl {
($($t:ty)*) => ($(
#[unstable(feature = "new_range_api", issue = "125687")]
impl ExactSizeIterator for IterRangeInclusive<$t> { }
impl ExactSizeIterator for RangeInclusiveIter<$t> { }
)*)
}

Expand All @@ -294,14 +294,14 @@ range_incl_exact_iter_impl! {
/// By-value [`RangeFrom`] iterator.
#[unstable(feature = "new_range_api", issue = "125687")]
#[derive(Debug, Clone)]
pub struct IterRangeFrom<A> {
pub struct RangeFromIter<A> {
start: A,
/// Whether the first element of the iterator has yielded.
/// Only used when overflow checks are enabled.
first: bool,
}

impl<A: Step> IterRangeFrom<A> {
impl<A: Step> RangeFromIter<A> {
/// Returns the remainder of the range being iterated over.
#[inline]
#[rustc_inherit_overflow_checks]
Expand All @@ -317,7 +317,7 @@ impl<A: Step> IterRangeFrom<A> {
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> Iterator for IterRangeFrom<A> {
impl<A: Step> Iterator for RangeFromIter<A> {
type Item = A;

#[inline]
Expand Down Expand Up @@ -366,17 +366,17 @@ impl<A: Step> Iterator for IterRangeFrom<A> {
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<A: TrustedStep> TrustedLen for IterRangeFrom<A> {}
unsafe impl<A: TrustedStep> TrustedLen for RangeFromIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> FusedIterator for IterRangeFrom<A> {}
impl<A: Step> FusedIterator for RangeFromIter<A> {}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<A: Step> IntoIterator for RangeFrom<A> {
type Item = A;
type IntoIter = IterRangeFrom<A>;
type IntoIter = RangeFromIter<A>;

fn into_iter(self) -> Self::IntoIter {
IterRangeFrom { start: self.start, first: true }
RangeFromIter { start: self.start, first: true }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#![crate_type = "lib"]
#![feature(new_range_api)]
use std::range::{IterRangeFrom, RangeFrom};
use std::range::{RangeFrom, RangeFromIter};

// CHECK-LABEL: @iterrangefrom_remainder(
#[no_mangle]
pub unsafe fn iterrangefrom_remainder(x: IterRangeFrom<i32>) -> RangeFrom<i32> {
pub unsafe fn iterrangefrom_remainder(x: RangeFromIter<i32>) -> RangeFrom<i32> {
// DEBUG: i32 noundef %x
// NOCHECKS: i32 noundef returned %x
// DEBUG: br i1
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/new-range/enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() {
let c: core::range::RangeInclusive<u8> = 4..=5;
let d: core::range::RangeToInclusive<u8> = ..=3;

let _: core::range::IterRangeFrom<u8> = a.into_iter();
let _: core::range::IterRange<u8> = b.into_iter();
let _: core::range::IterRangeInclusive<u8> = c.into_iter();
let _: core::range::RangeFromIter<u8> = a.into_iter();
let _: core::range::RangeIter<u8> = b.into_iter();
let _: core::range::RangeInclusiveIter<u8> = c.into_iter();
// RangeToInclusive has no Iterator implementation
}
Loading