Skip to content

Commit

Permalink
Add cfg to impl RangeBounds only in versions after it was stabilized
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismit3s committed Mar 22, 2022
1 parent 4b92422 commit 99ab2c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate autocfg;

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

fn main() {
Expand All @@ -9,5 +10,9 @@ fn main() {
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::rerun_path("build.rs");
}
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn unsigned<T: ToPrimitive>(x: &T) -> Option<u64> {
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for Range<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
Expand Down Expand Up @@ -173,6 +174,7 @@ where
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeInclusive<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.range.state)
Expand Down Expand Up @@ -248,6 +250,7 @@ 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)
Expand Down Expand Up @@ -320,6 +323,7 @@ where
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeStepInclusive<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
Expand Down Expand Up @@ -377,6 +381,7 @@ where
}
}

#[cfg(rustc_1_28)]
impl<A> RangeBounds<A> for RangeFrom<A> {
fn start_bound(&self) -> Bound<&A> {
Bound::Included(&self.state)
Expand Down Expand Up @@ -430,6 +435,7 @@ where
}
}

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

0 comments on commit 99ab2c5

Please sign in to comment.