mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
library: Rename IterRange* to Range*Iter
There is a weak convention in the ecosystem that `IterFoos` is an iterator yielding items of type `Foo` (e.g. `bitflags` `IterNames`, `hashbrown` `IterBuckets`), while `FooIter` is an iterator over `Foo` from an `.iter()` or `.into_iter()` method (e.g. `memchr` `OneIter`, `regex` `SetMatchesIter`). Rename `IterRange`, `IterRangeInclusive`, and `IterRangeFrom` to `RangeIter`, `RangeInclusiveIter`, and `RangeInclusiveIter` to match this. Tracking issue: RUST-125687 (`new_range_api`)
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
|
||||
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;
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
/// 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 }
|
||||
@@ -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;
|
||||
}
|
||||
)*)
|
||||
@@ -50,7 +50,7 @@ unsafe impl TrustedRandomAccessNoCoerce for IterRange<$t> {
|
||||
}
|
||||
|
||||
#[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]
|
||||
@@ -118,7 +118,7 @@ unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
|
||||
}
|
||||
|
||||
#[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()
|
||||
@@ -136,27 +136,27 @@ fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
|
||||
}
|
||||
|
||||
#[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`.
|
||||
@@ -170,7 +170,7 @@ pub fn remainder(self) -> Option<RangeInclusive<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]
|
||||
@@ -226,7 +226,7 @@ fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
|
||||
}
|
||||
|
||||
#[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()
|
||||
@@ -244,18 +244,18 @@ fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
|
||||
}
|
||||
|
||||
#[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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,14 +270,14 @@ fn into_iter(self) -> Self::IntoIter {
|
||||
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> { }
|
||||
)*)
|
||||
}
|
||||
|
||||
@@ -294,14 +294,14 @@ impl ExactSizeIterator for IterRangeInclusive<$t> { }
|
||||
/// 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]
|
||||
@@ -317,7 +317,7 @@ pub fn remainder(self) -> RangeFrom<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]
|
||||
@@ -366,17 +366,17 @@ fn nth(&mut self, n: usize) -> Option<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 }
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user