Skip to content

Commit 24cc902

Browse files
committed
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.
1 parent 15a8a29 commit 24cc902

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/libcollections/range.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub trait RangeArgument<T> {
3535
}
3636
}
3737

38+
// FIXME add inclusive ranges to RangeArgument
3839

3940
impl<T> RangeArgument<T> for RangeFull {}
4041

src/libcore/iter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,9 @@ macro_rules! range_exact_iter_impl {
44174417
#[stable(feature = "rust1", since = "1.0.0")]
44184418
impl ExactSizeIterator for ops::Range<$t> { }
44194419

4420-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
4420+
#[unstable(feature = "inclusive_range",
4421+
reason = "recently added, follows RFC",
4422+
issue = "28237")]
44214423
impl ExactSizeIterator for ops::RangeInclusive<$t> { }
44224424
)*)
44234425
}

src/libcore/ops.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
14681468

14691469
/// An unbounded range.
14701470
#[derive(Copy, Clone, PartialEq, Eq)]
1471-
#[cfg_attr(stage0, lang = "range_full")] // TODO remove attribute after next snapshot
1471+
#[cfg_attr(stage0, lang = "range_full")] // FIXME remove attribute after next snapshot
14721472
#[stable(feature = "rust1", since = "1.0.0")]
14731473
pub struct RangeFull;
14741474

@@ -1481,7 +1481,7 @@ impl fmt::Debug for RangeFull {
14811481

14821482
/// A (half-open) range which is bounded at both ends.
14831483
#[derive(Clone, PartialEq, Eq)]
1484-
#[cfg_attr(stage0, lang = "range")] // TODO remove attribute after next snapshot
1484+
#[cfg_attr(stage0, lang = "range")] // FIXME remove attribute after next snapshot
14851485
#[stable(feature = "rust1", since = "1.0.0")]
14861486
pub struct Range<Idx> {
14871487
/// The lower bound of the range (inclusive).
@@ -1501,7 +1501,7 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
15011501

15021502
/// A range which is only bounded below.
15031503
#[derive(Clone, PartialEq, Eq)]
1504-
#[cfg_attr(stage0, lang = "range_from")] // TODO remove attribute after next snapshot
1504+
#[cfg_attr(stage0, lang = "range_from")] // FIXME remove attribute after next snapshot
15051505
#[stable(feature = "rust1", since = "1.0.0")]
15061506
pub struct RangeFrom<Idx> {
15071507
/// The lower bound of the range (inclusive).
@@ -1518,7 +1518,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
15181518

15191519
/// A range which is only bounded above.
15201520
#[derive(Copy, Clone, PartialEq, Eq)]
1521-
#[cfg_attr(stage0, lang = "range_to")] // TODO remove attribute after next snapshot
1521+
#[cfg_attr(stage0, lang = "range_to")] // FIXME remove attribute after next snapshot
15221522
#[stable(feature = "rust1", since = "1.0.0")]
15231523
pub struct RangeTo<Idx> {
15241524
/// The upper bound of the range (exclusive).
@@ -1586,7 +1586,9 @@ impl<Idx: PartialOrd + One + Sub<Output=Idx>> From<Range<Idx>> for RangeInclusiv
15861586
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
15871587
pub struct RangeToInclusive<Idx> {
15881588
/// The upper bound of the range (inclusive)
1589-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
1589+
#[unstable(feature = "inclusive_range",
1590+
reason = "recently added, follows RFC",
1591+
issue = "28237")]
15901592
pub end: Idx,
15911593
}
15921594

src/libcore/slice.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! {
533533
panic!("slice index starts at {} but ends at {}", index, end);
534534
}
535535

536+
// FIXME implement indexing with inclusive ranges
537+
536538
#[stable(feature = "rust1", since = "1.0.0")]
537539
impl<T> ops::Index<ops::Range<usize>> for [T] {
538540
type Output = [T];

0 commit comments

Comments
 (0)