Skip to content
Merged
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
16 changes: 12 additions & 4 deletions library/core/src/range/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ use crate::{intrinsics, mem};
pub struct RangeIter<A>(legacy::Range<A>);

impl<A> RangeIter<A> {
#[unstable(feature = "new_range_api", issue = "125687")]
#[unstable(feature = "new_range_remainder", issue = "154458")]
/// Returns the remainder of the range being iterated over.
///
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// #![feature(new_range_remainder)]
///
/// let range = core::range::Range::from(3..11);
/// let mut iter = range.into_iter();
/// assert_eq!(iter.clone().remainder(), range);
Expand Down Expand Up @@ -175,7 +178,10 @@ impl<A: Step> RangeInclusiveIter<A> {
/// If the iterator is exhausted or empty, returns `None`.
///
/// # Examples
///
/// ```
/// #![feature(new_range_remainder)]
///
/// let range = core::range::RangeInclusive::from(3..=11);
/// let mut iter = range.into_iter();
/// assert_eq!(iter.clone().remainder().unwrap(), range);
Expand All @@ -184,7 +190,7 @@ impl<A: Step> RangeInclusiveIter<A> {
/// iter.by_ref().for_each(drop);
/// assert!(iter.remainder().is_none());
/// ```
#[stable(feature = "new_range_inclusive_api", since = "1.95.0")]
#[unstable(feature = "new_range_remainder", issue = "154458")]
pub fn remainder(self) -> Option<RangeInclusive<A>> {
if self.0.is_empty() {
return None;
Expand Down Expand Up @@ -330,8 +336,10 @@ impl<A: Step> RangeFromIter<A> {
/// Returns the remainder of the range being iterated over.
///
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// #![feature(new_range_remainder)]
///
/// let range = core::range::RangeFrom::from(3..);
/// let mut iter = range.into_iter();
/// assert_eq!(iter.clone().remainder(), range);
Expand All @@ -340,7 +348,7 @@ impl<A: Step> RangeFromIter<A> {
/// ```
#[inline]
#[rustc_inherit_overflow_checks]
#[unstable(feature = "new_range_api", issue = "125687")]
#[unstable(feature = "new_range_remainder", issue = "154458")]
pub fn remainder(self) -> RangeFrom<A> {
// Need to handle this case even if overflow-checks are disabled,
// because a `RangeFromIter` could be exhausted in a crate with
Expand Down
1 change: 1 addition & 0 deletions tests/codegen-llvm/fromrangeiter-overflow-checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#![crate_type = "lib"]
#![feature(new_range_api)]
#![feature(new_range_remainder)]

use std::range::RangeFrom;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/iterators/rangefrom-overflow-debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ needs-unwind
//@ compile-flags: -O -C debug_assertions=yes

#![feature(new_range_api)]
#![feature(new_range_remainder)]

use std::panic;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/iterators/rangefrom-overflow-ndebug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ run-pass
//@ compile-flags: -O -C debug_assertions=no

#![feature(new_range_api)]
#![feature(new_range_remainder)]

fn main() {
let mut it = core::range::RangeFrom::from(u8::MAX..).into_iter();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/iterators/rangefrom-overflow-overflow-checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ needs-unwind
//@ compile-flags: -O -C overflow-checks=yes

#![feature(new_range_api)]
#![feature(new_range_remainder)]

use std::panic;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/range/new_range_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn range_inclusive(mut r: RangeInclusive<usize>) {

let mut i = r.into_iter();
i.next();
i.remainder();
i.remainder(); //~ ERROR unstable
}

fn range_to_inclusive(mut r: RangeToInclusive<usize>) {
Expand Down
18 changes: 14 additions & 4 deletions tests/ui/range/new_range_stability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,26 @@ LL | use std::range::RangeIter;
= help: add `#![feature(new_range_api)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_api`
error[E0658]: use of unstable library feature `new_range_remainder`
--> $DIR/new_range_stability.rs:22:7
|
LL | i.remainder();
| ^^^^^^^^^
|
= note: see issue #154458 <https://github.com/rust-lang/rust/issues/154458> for more information
= help: add `#![feature(new_range_remainder)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `new_range_remainder`
--> $DIR/new_range_stability.rs:43:7
|
LL | i.remainder();
| ^^^^^^^^^
|
= note: see issue #125687 <https://github.com/rust-lang/rust/issues/125687> for more information
= help: add `#![feature(new_range_api)]` to the crate attributes to enable
= note: see issue #154458 <https://github.com/rust-lang/rust/issues/154458> for more information
= help: add `#![feature(new_range_remainder)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0658`.
Loading