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*<usize>`, but not yet `Range*Inclusive<usize>`. 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.
This commit is contained in:
parent
15a8a296b7
commit
24cc90262b
@ -35,6 +35,7 @@ pub trait RangeArgument<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME add inclusive ranges to RangeArgument
|
||||
|
||||
impl<T> RangeArgument<T> for RangeFull {}
|
||||
|
||||
|
@ -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> { }
|
||||
)*)
|
||||
}
|
||||
|
@ -1468,7 +1468,7 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
|
||||
|
||||
/// 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<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
@ -1501,7 +1501,7 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
|
||||
|
||||
/// 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<Idx> {
|
||||
/// The lower bound of the range (inclusive).
|
||||
@ -1518,7 +1518,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
|
||||
|
||||
/// 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<Idx> {
|
||||
/// The upper bound of the range (exclusive).
|
||||
@ -1586,7 +1586,9 @@ impl<Idx: PartialOrd + One + Sub<Output=Idx>> From<Range<Idx>> for RangeInclusiv
|
||||
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
|
||||
pub struct RangeToInclusive<Idx> {
|
||||
/// 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,
|
||||
}
|
||||
|
||||
|
@ -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<T> ops::Index<ops::Range<usize>> for [T] {
|
||||
type Output = [T];
|
||||
|
Loading…
x
Reference in New Issue
Block a user