Skip to content

Commit 62172c4

Browse files
committed
Reduce duplication
Extract code for checking range validity into helper functions, and use macros to implement SliceIndex for the new range types from `std::range`.
1 parent d2b6a1d commit 62172c4

File tree

3 files changed

+334
-449
lines changed

3 files changed

+334
-449
lines changed

library/core/src/range.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,20 @@ impl<T> IntoBounds<T> for RangeToInclusive<T> {
639639
(Unbounded, Included(self.last))
640640
}
641641
}
642+
643+
#[unstable(feature = "new_range_api", issue = "125687")]
644+
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
645+
impl<T> const From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> {
646+
#[inline]
647+
fn from(value: RangeToInclusive<T>) -> Self {
648+
Self { end: value.last }
649+
}
650+
}
651+
#[unstable(feature = "new_range_api", issue = "125687")]
652+
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
653+
impl<T> const From<legacy::RangeToInclusive<T>> for RangeToInclusive<T> {
654+
#[inline]
655+
fn from(value: legacy::RangeToInclusive<T>) -> Self {
656+
Self { last: value.end }
657+
}
658+
}

0 commit comments

Comments
 (0)