From 24cc90262bd5ec52aa421103ef7c89a0697b046d Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Wed, 13 Jan 2016 13:12:16 -0500 Subject: [PATCH] note work still to be done In particular, uses of inclusive ranges within the standard library are still waiting. Slices and collections can be sliced with `usize` and `Range*`, but not yet `Range*Inclusive`. Also, we need to figure out what to do about `RangeArgument`. Currently it has `start()` and `end()` methods which are pretty much identical to `Range::start` and `Range::end`. For the same reason as Range itself, these methods can't express a range such as `0...255u8` without overflow. The easiest choice, it seems to me, is either changing the meaning of `end()` to be inclusive, or adding a new method, say `last()`, that is inclusive and specifying that `end()` returns `None` in cases where it would overflow. Changing the semantics would be a breaking change, but `RangeArgument` is unstable so maybe we should do it anyway. --- src/libcollections/range.rs | 1 + src/libcore/iter.rs | 4 +++- src/libcore/ops.rs | 12 +++++++----- src/libcore/slice.rs | 2 ++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libcollections/range.rs b/src/libcollections/range.rs index afcd779ddf19..4e39191b472e 100644 --- a/src/libcollections/range.rs +++ b/src/libcollections/range.rs @@ -35,6 +35,7 @@ pub trait RangeArgument { } } +// FIXME add inclusive ranges to RangeArgument impl RangeArgument for RangeFull {} diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 1f5ef6be0bc4..305f32e26374 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -4417,7 +4417,9 @@ macro_rules! range_exact_iter_impl { #[stable(feature = "rust1", since = "1.0.0")] impl ExactSizeIterator for ops::Range<$t> { } - #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] + #[unstable(feature = "inclusive_range", + reason = "recently added, follows RFC", + issue = "28237")] impl ExactSizeIterator for ops::RangeInclusive<$t> { } )*) } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index b5bec3169474..e5a51c98acac 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1468,7 +1468,7 @@ pub trait IndexMut: Index { /// An unbounded range. #[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(stage0, lang = "range_full")] // TODO remove attribute after next snapshot +#[cfg_attr(stage0, lang = "range_full")] // FIXME remove attribute after next snapshot #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFull; @@ -1481,7 +1481,7 @@ impl fmt::Debug for RangeFull { /// A (half-open) range which is bounded at both ends. #[derive(Clone, PartialEq, Eq)] -#[cfg_attr(stage0, lang = "range")] // TODO remove attribute after next snapshot +#[cfg_attr(stage0, lang = "range")] // FIXME remove attribute after next snapshot #[stable(feature = "rust1", since = "1.0.0")] pub struct Range { /// The lower bound of the range (inclusive). @@ -1501,7 +1501,7 @@ impl fmt::Debug for Range { /// A range which is only bounded below. #[derive(Clone, PartialEq, Eq)] -#[cfg_attr(stage0, lang = "range_from")] // TODO remove attribute after next snapshot +#[cfg_attr(stage0, lang = "range_from")] // FIXME remove attribute after next snapshot #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFrom { /// The lower bound of the range (inclusive). @@ -1518,7 +1518,7 @@ impl fmt::Debug for RangeFrom { /// A range which is only bounded above. #[derive(Copy, Clone, PartialEq, Eq)] -#[cfg_attr(stage0, lang = "range_to")] // TODO remove attribute after next snapshot +#[cfg_attr(stage0, lang = "range_to")] // FIXME remove attribute after next snapshot #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeTo { /// The upper bound of the range (exclusive). @@ -1586,7 +1586,9 @@ impl> From> for RangeInclusiv #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] pub struct RangeToInclusive { /// The upper bound of the range (inclusive) - #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] + #[unstable(feature = "inclusive_range", + reason = "recently added, follows RFC", + issue = "28237")] pub end: Idx, } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index afda70f4fcc0..73466a849dc8 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -533,6 +533,8 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! { panic!("slice index starts at {} but ends at {}", index, end); } +// FIXME implement indexing with inclusive ranges + #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T];