Move RangeIndex to associated types (avoids old impl check)

This commit is contained in:
Manish Goregaokar 2015-01-31 15:55:05 +05:30
parent 1d7b1e5c31
commit 40c9e7f72e
2 changed files with 13 additions and 14 deletions

View file

@ -5,7 +5,6 @@
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![feature(plugin)] #![feature(plugin)]
#![feature(int_uint)] #![feature(int_uint)]
#![feature(old_impl_check)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![deny(unused_imports)] #![deny(unused_imports)]

View file

@ -9,12 +9,14 @@ use std::num;
use std::num::Int; use std::num::Int;
/// An index type to be used by a `Range` /// An index type to be used by a `Range`
pub trait RangeIndex<T>: Int + fmt::Show { pub trait RangeIndex: Int + fmt::Show {
fn new(x: T) -> Self; type Index;
fn get(self) -> T; fn new(x: Self::Index) -> Self;
fn get(self) -> Self::Index;
} }
impl RangeIndex<int> for int { impl RangeIndex for int {
type Index = int;
#[inline] #[inline]
fn new(x: int) -> int { x } fn new(x: int) -> int { x }
@ -37,7 +39,8 @@ macro_rules! int_range_index {
} }
} }
impl RangeIndex<$T> for $Self { impl RangeIndex for $Self {
type Index = $T;
#[inline] #[inline]
fn new(x: $T) -> $Self { fn new(x: $T) -> $Self {
$Self(x) $Self(x)
@ -191,8 +194,7 @@ pub struct Range<I> {
length: I, length: I,
} }
#[old_impl_check] impl<I: RangeIndex> fmt::Show for Range<I> {
impl<I: RangeIndex<T>, T> fmt::Show for Range<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[{:?} .. {:?})", self.begin(), self.end()) write!(f, "[{:?} .. {:?})", self.begin(), self.end())
} }
@ -203,11 +205,11 @@ pub struct EachIndex<T, I> {
it: iter::Range<T>, it: iter::Range<T>,
} }
pub fn each_index<T: Int, I: RangeIndex<T>>(start: I, stop: I) -> EachIndex<T, I> { pub fn each_index<T: Int, I: RangeIndex<Index=T>>(start: I, stop: I) -> EachIndex<T, I> {
EachIndex { it: iter::range(start.get(), stop.get()) } EachIndex { it: iter::range(start.get(), stop.get()) }
} }
impl<T: Int, I: RangeIndex<T>> Iterator for EachIndex<T, I> { impl<T: Int, I: RangeIndex<Index=T>> Iterator for EachIndex<T, I> {
type Item = I; type Item = I;
#[inline] #[inline]
@ -221,8 +223,7 @@ impl<T: Int, I: RangeIndex<T>> Iterator for EachIndex<T, I> {
} }
} }
#[old_impl_check] impl<I: RangeIndex> Range<I> {
impl<I: RangeIndex<T>, T> Range<I> {
/// Create a new range from beginning and length offsets. This could be /// Create a new range from beginning and length offsets. This could be
/// denoted as `[begin, begin + length)`. /// denoted as `[begin, begin + length)`.
/// ///
@ -359,8 +360,7 @@ impl<I: RangeIndex<T>, T> Range<I> {
} }
/// Methods for `Range`s with indices based on integer values /// Methods for `Range`s with indices based on integer values
#[old_impl_check] impl<T: Int, I: RangeIndex<Index=T>> Range<I> {
impl<T: Int, I: RangeIndex<T>> Range<I> {
/// Returns an iterater that increments over `[begin, end)`. /// Returns an iterater that increments over `[begin, end)`.
#[inline] #[inline]
pub fn each_index(&self) -> EachIndex<T, I> { pub fn each_index(&self) -> EachIndex<T, I> {