Skip to content

Commit

Permalink
Remove RangeBounds from RangeStep*
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismit3s committed Apr 20, 2022
1 parent 99ab2c5 commit 20a4975
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
7 changes: 4 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
extern crate autocfg;

use autocfg::AutoCfg;
use std::env;

fn main() {
let autocfg = autocfg::new();

// If the "i128" feature is explicity requested, don't bother probing for it.
// It will still cause a build error if that was set improperly.
if env::var_os("CARGO_FEATURE_I128").is_some() || autocfg::new().probe_type("i128") {
if env::var_os("CARGO_FEATURE_I128").is_some() || autocfg.probe_type("i128") {
autocfg::emit("has_i128");
}

// The RangeBounds trait was stabilized in 1.28, so from that version onwards we
// implement that trait.
AutoCfg::new().unwrap().emit_rustc_version(1, 28);
autocfg.emit_rustc_version(1, 28);

autocfg::rerun_path("build.rs");
}
38 changes: 4 additions & 34 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ extern crate std;
extern crate num_integer as integer;
extern crate num_traits as traits;

use core::ops::{Add, Bound, RangeBounds, Sub};
use core::ops::{Add, Sub};
use core::usize;
use integer::Integer;
use traits::{CheckedAdd, One, ToPrimitive, Zero};

#[cfg(rustc_1_28)]
use core::ops::{Bound, RangeBounds};

/// An iterator over the range [start, stop)
#[derive(Clone)]
pub struct Range<A> {
Expand Down Expand Up @@ -250,17 +253,6 @@ pub struct RangeStep<A> {
rev: bool,
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeStep<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
}

fn end_bound(&self) -> Bound<&A> {
Bound::Excluded(&self.stop)
}
}

/// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping.
#[inline]
pub fn range_step<A>(start: A, stop: A, step: A) -> RangeStep<A>
Expand Down Expand Up @@ -323,17 +315,6 @@ where
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeStepInclusive<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
}

fn end_bound(&self) -> Bound<&A> {
Bound::Included(&self.stop)
}
}

impl<A> Iterator for RangeStepInclusive<A>
where
A: CheckedAdd + PartialOrd + Clone + PartialEq,
Expand Down Expand Up @@ -435,17 +416,6 @@ where
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeStepFrom<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
}

fn end_bound(&self) -> Bound<&A> {
Bound::Unbounded
}
}

impl<A> Iterator for RangeStepFrom<A>
where
A: Add<A, Output = A> + Clone,
Expand Down

0 comments on commit 20a4975

Please sign in to comment.