Skip to content

Commit 70a56d0

Browse files
committed
Add a new type parameter to new Range types
1 parent f29256d commit 70a56d0

2 files changed

Lines changed: 108 additions & 92 deletions

File tree

library/core/src/ops/range.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,11 @@ impl<T: Clone> Bound<&T> {
817817
#[stable(feature = "collections_range", since = "1.28.0")]
818818
#[rustc_diagnostic_item = "RangeBounds"]
819819
#[rustc_const_unstable(feature = "const_range", issue = "none")]
820-
pub const trait RangeBounds<T: ?Sized> {
820+
pub const trait RangeBounds<
821+
Start: ?Sized,
822+
#[unstable(feature = "new_range_end_bound", issue = "155456")] End: ?Sized = Start,
823+
>
824+
{
821825
/// Start index bound.
822826
///
823827
/// Returns the start value as a `Bound`.
@@ -832,7 +836,7 @@ pub const trait RangeBounds<T: ?Sized> {
832836
/// assert_eq!((3..10).start_bound(), Included(&3));
833837
/// ```
834838
#[stable(feature = "collections_range", since = "1.28.0")]
835-
fn start_bound(&self) -> Bound<&T>;
839+
fn start_bound(&self) -> Bound<&Start>;
836840

837841
/// End index bound.
838842
///
@@ -848,7 +852,7 @@ pub const trait RangeBounds<T: ?Sized> {
848852
/// assert_eq!((3..10).end_bound(), Excluded(&10));
849853
/// ```
850854
#[stable(feature = "collections_range", since = "1.28.0")]
851-
fn end_bound(&self) -> Bound<&T>;
855+
fn end_bound(&self) -> Bound<&End>;
852856

853857
/// Returns `true` if `item` is contained in the range.
854858
///
@@ -867,8 +871,9 @@ pub const trait RangeBounds<T: ?Sized> {
867871
#[stable(feature = "range_contains", since = "1.35.0")]
868872
fn contains<U>(&self, item: &U) -> bool
869873
where
870-
T: [const] PartialOrd<U>,
871-
U: ?Sized + [const] PartialOrd<T>,
874+
Start: [const] PartialOrd<U>,
875+
End: [const] PartialOrd<U>,
876+
U: ?Sized + [const] PartialOrd<Start> + [const] PartialOrd<End>,
872877
{
873878
(match self.start_bound() {
874879
Included(start) => start <= item,
@@ -935,7 +940,7 @@ pub const trait RangeBounds<T: ?Sized> {
935940
#[unstable(feature = "range_bounds_is_empty", issue = "137300")]
936941
fn is_empty(&self) -> bool
937942
where
938-
T: [const] PartialOrd,
943+
Start: [const] PartialOrd<End>,
939944
{
940945
!match (self.start_bound(), self.end_bound()) {
941946
(Unbounded, _) | (_, Unbounded) => true,
@@ -954,7 +959,11 @@ pub const trait RangeBounds<T: ?Sized> {
954959
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
955960
#[unstable(feature = "range_into_bounds", issue = "136903")]
956961
#[rustc_const_unstable(feature = "const_range", issue = "none")]
957-
pub const trait IntoBounds<T>: [const] RangeBounds<T> {
962+
pub const trait IntoBounds<
963+
Start,
964+
#[unstable(feature = "new_range_end_bound", issue = "155456")] End = Start,
965+
>: [const] RangeBounds<Start, End>
966+
{
958967
/// Convert this range into the start and end bounds.
959968
/// Returns `(start_bound, end_bound)`.
960969
///
@@ -968,7 +977,7 @@ pub const trait IntoBounds<T>: [const] RangeBounds<T> {
968977
/// assert_eq!((0..5).into_bounds(), (Included(0), Excluded(5)));
969978
/// assert_eq!((..=7).into_bounds(), (Unbounded, Included(7)));
970979
/// ```
971-
fn into_bounds(self) -> (Bound<T>, Bound<T>);
980+
fn into_bounds(self) -> (Bound<Start>, Bound<End>);
972981

973982
/// Compute the intersection of `self` and `other`.
974983
///
@@ -997,11 +1006,12 @@ pub const trait IntoBounds<T>: [const] RangeBounds<T> {
9971006
/// assert!(!(-12..387).intersect(0..256).is_empty());
9981007
/// assert!((1..5).intersect(6..).is_empty());
9991008
/// ```
1000-
fn intersect<R>(self, other: R) -> (Bound<T>, Bound<T>)
1009+
fn intersect<R>(self, other: R) -> (Bound<Start>, Bound<End>)
10011010
where
10021011
Self: Sized,
1003-
T: [const] Ord + [const] Destruct,
1004-
R: Sized + [const] IntoBounds<T>,
1012+
Start: [const] Ord + [const] Destruct,
1013+
End: [const] Ord + [const] Destruct,
1014+
R: Sized + [const] IntoBounds<Start, End>,
10051015
{
10061016
let (self_start, self_end) = IntoBounds::into_bounds(self);
10071017
let (other_start, other_end) = IntoBounds::into_bounds(other);

0 commit comments

Comments
 (0)