@@ -96,7 +96,7 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
96
96
}
97
97
}
98
98
99
- impl < Idx : PartialOrd < Idx > > Range < Idx > {
99
+ impl < Idx : ~ const PartialOrd < Idx > > Range < Idx > {
100
100
/// Returns `true` if `item` is contained in the range.
101
101
///
102
102
/// # Examples
@@ -116,10 +116,11 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
116
116
/// assert!(!(f32::NAN..1.0).contains(&0.5));
117
117
/// ```
118
118
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
119
- pub fn contains < U > ( & self , item : & U ) -> bool
119
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
120
+ pub const fn contains < U > ( & self , item : & U ) -> bool
120
121
where
121
- Idx : PartialOrd < U > ,
122
- U : ?Sized + PartialOrd < Idx > ,
122
+ Idx : ~ const PartialOrd < U > ,
123
+ U : ?Sized + ~ const PartialOrd < Idx > ,
123
124
{
124
125
<Self as RangeBounds < Idx > >:: contains ( self , item)
125
126
}
@@ -142,7 +143,8 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
142
143
/// assert!( (f32::NAN..5.0).is_empty());
143
144
/// ```
144
145
#[ stable( feature = "range_is_empty" , since = "1.47.0" ) ]
145
- pub fn is_empty ( & self ) -> bool {
146
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
147
+ pub const fn is_empty ( & self ) -> bool {
146
148
!( self . start < self . end )
147
149
}
148
150
}
@@ -199,7 +201,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
199
201
}
200
202
}
201
203
202
- impl < Idx : PartialOrd < Idx > > RangeFrom < Idx > {
204
+ impl < Idx : ~ const PartialOrd < Idx > > RangeFrom < Idx > {
203
205
/// Returns `true` if `item` is contained in the range.
204
206
///
205
207
/// # Examples
@@ -214,10 +216,11 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
214
216
/// assert!(!(f32::NAN..).contains(&0.5));
215
217
/// ```
216
218
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
217
- pub fn contains < U > ( & self , item : & U ) -> bool
219
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
220
+ pub const fn contains < U > ( & self , item : & U ) -> bool
218
221
where
219
- Idx : PartialOrd < U > ,
220
- U : ?Sized + PartialOrd < Idx > ,
222
+ Idx : ~ const PartialOrd < U > ,
223
+ U : ?Sized + ~ const PartialOrd < Idx > ,
221
224
{
222
225
<Self as RangeBounds < Idx > >:: contains ( self , item)
223
226
}
@@ -280,7 +283,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeTo<Idx> {
280
283
}
281
284
}
282
285
283
- impl < Idx : PartialOrd < Idx > > RangeTo < Idx > {
286
+ impl < Idx : ~ const PartialOrd < Idx > > RangeTo < Idx > {
284
287
/// Returns `true` if `item` is contained in the range.
285
288
///
286
289
/// # Examples
@@ -295,10 +298,11 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
295
298
/// assert!(!(..f32::NAN).contains(&0.5));
296
299
/// ```
297
300
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
298
- pub fn contains < U > ( & self , item : & U ) -> bool
301
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
302
+ pub const fn contains < U > ( & self , item : & U ) -> bool
299
303
where
300
- Idx : PartialOrd < U > ,
301
- U : ?Sized + PartialOrd < Idx > ,
304
+ Idx : ~ const PartialOrd < U > ,
305
+ U : ?Sized + ~ const PartialOrd < Idx > ,
302
306
{
303
307
<Self as RangeBounds < Idx > >:: contains ( self , item)
304
308
}
@@ -437,7 +441,8 @@ impl<Idx> RangeInclusive<Idx> {
437
441
/// ```
438
442
#[ stable( feature = "inclusive_range_methods" , since = "1.27.0" ) ]
439
443
#[ inline]
440
- pub fn into_inner ( self ) -> ( Idx , Idx ) {
444
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
445
+ pub const fn into_inner ( self ) -> ( Idx , Idx ) {
441
446
( self . start , self . end )
442
447
}
443
448
}
@@ -469,7 +474,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
469
474
}
470
475
}
471
476
472
- impl < Idx : PartialOrd < Idx > > RangeInclusive < Idx > {
477
+ impl < Idx : ~ const PartialOrd < Idx > > RangeInclusive < Idx > {
473
478
/// Returns `true` if `item` is contained in the range.
474
479
///
475
480
/// # Examples
@@ -500,10 +505,11 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
500
505
/// assert!(!r.contains(&3) && !r.contains(&5));
501
506
/// ```
502
507
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
503
- pub fn contains < U > ( & self , item : & U ) -> bool
508
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
509
+ pub const fn contains < U > ( & self , item : & U ) -> bool
504
510
where
505
- Idx : PartialOrd < U > ,
506
- U : ?Sized + PartialOrd < Idx > ,
511
+ Idx : ~ const PartialOrd < U > ,
512
+ U : ?Sized + ~ const PartialOrd < Idx > ,
507
513
{
508
514
<Self as RangeBounds < Idx > >:: contains ( self , item)
509
515
}
@@ -535,8 +541,9 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
535
541
/// assert!(r.is_empty());
536
542
/// ```
537
543
#[ stable( feature = "range_is_empty" , since = "1.47.0" ) ]
544
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
538
545
#[ inline]
539
- pub fn is_empty ( & self ) -> bool {
546
+ pub const fn is_empty ( & self ) -> bool {
540
547
self . exhausted || !( self . start <= self . end )
541
548
}
542
549
}
@@ -598,7 +605,7 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
598
605
}
599
606
}
600
607
601
- impl < Idx : PartialOrd < Idx > > RangeToInclusive < Idx > {
608
+ impl < Idx : ~ const PartialOrd < Idx > > RangeToInclusive < Idx > {
602
609
/// Returns `true` if `item` is contained in the range.
603
610
///
604
611
/// # Examples
@@ -613,10 +620,11 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
613
620
/// assert!(!(..=f32::NAN).contains(&0.5));
614
621
/// ```
615
622
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
616
- pub fn contains < U > ( & self , item : & U ) -> bool
623
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
624
+ pub const fn contains < U > ( & self , item : & U ) -> bool
617
625
where
618
- Idx : PartialOrd < U > ,
619
- U : ?Sized + PartialOrd < Idx > ,
626
+ Idx : ~ const PartialOrd < U > ,
627
+ U : ?Sized + ~ const PartialOrd < Idx > ,
620
628
{
621
629
<Self as RangeBounds < Idx > >:: contains ( self , item)
622
630
}
@@ -757,6 +765,7 @@ impl<T: Clone> Bound<&T> {
757
765
/// `RangeBounds` is implemented by Rust's built-in range types, produced
758
766
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
759
767
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
768
+ #[ const_trait]
760
769
pub trait RangeBounds < T : ?Sized > {
761
770
/// Start index bound.
762
771
///
@@ -809,8 +818,8 @@ pub trait RangeBounds<T: ?Sized> {
809
818
#[ stable( feature = "range_contains" , since = "1.35.0" ) ]
810
819
fn contains < U > ( & self , item : & U ) -> bool
811
820
where
812
- T : PartialOrd < U > ,
813
- U : ?Sized + PartialOrd < T > ,
821
+ T : ~ const PartialOrd < U > ,
822
+ U : ?Sized + ~ const PartialOrd < T > ,
814
823
{
815
824
( match self . start_bound ( ) {
816
825
Included ( start) => start <= item,
@@ -827,7 +836,8 @@ pub trait RangeBounds<T: ?Sized> {
827
836
use self :: Bound :: { Excluded , Included , Unbounded } ;
828
837
829
838
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
830
- impl < T : ?Sized > RangeBounds < T > for RangeFull {
839
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
840
+ impl < T : ?Sized > const RangeBounds < T > for RangeFull {
831
841
fn start_bound ( & self ) -> Bound < & T > {
832
842
Unbounded
833
843
}
@@ -837,7 +847,8 @@ impl<T: ?Sized> RangeBounds<T> for RangeFull {
837
847
}
838
848
839
849
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
840
- impl < T > RangeBounds < T > for RangeFrom < T > {
850
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
851
+ impl < T > const RangeBounds < T > for RangeFrom < T > {
841
852
fn start_bound ( & self ) -> Bound < & T > {
842
853
Included ( & self . start )
843
854
}
@@ -847,7 +858,8 @@ impl<T> RangeBounds<T> for RangeFrom<T> {
847
858
}
848
859
849
860
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
850
- impl < T > RangeBounds < T > for RangeTo < T > {
861
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
862
+ impl < T > const RangeBounds < T > for RangeTo < T > {
851
863
fn start_bound ( & self ) -> Bound < & T > {
852
864
Unbounded
853
865
}
@@ -857,7 +869,8 @@ impl<T> RangeBounds<T> for RangeTo<T> {
857
869
}
858
870
859
871
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
860
- impl < T > RangeBounds < T > for Range < T > {
872
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
873
+ impl < T > const RangeBounds < T > for Range < T > {
861
874
fn start_bound ( & self ) -> Bound < & T > {
862
875
Included ( & self . start )
863
876
}
@@ -867,7 +880,8 @@ impl<T> RangeBounds<T> for Range<T> {
867
880
}
868
881
869
882
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
870
- impl < T > RangeBounds < T > for RangeInclusive < T > {
883
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
884
+ impl < T > const RangeBounds < T > for RangeInclusive < T > {
871
885
fn start_bound ( & self ) -> Bound < & T > {
872
886
Included ( & self . start )
873
887
}
@@ -883,7 +897,8 @@ impl<T> RangeBounds<T> for RangeInclusive<T> {
883
897
}
884
898
885
899
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
886
- impl < T > RangeBounds < T > for RangeToInclusive < T > {
900
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
901
+ impl < T > const RangeBounds < T > for RangeToInclusive < T > {
887
902
fn start_bound ( & self ) -> Bound < & T > {
888
903
Unbounded
889
904
}
@@ -893,7 +908,8 @@ impl<T> RangeBounds<T> for RangeToInclusive<T> {
893
908
}
894
909
895
910
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
896
- impl < T > RangeBounds < T > for ( Bound < T > , Bound < T > ) {
911
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
912
+ impl < T > const RangeBounds < T > for ( Bound < T > , Bound < T > ) {
897
913
fn start_bound ( & self ) -> Bound < & T > {
898
914
match * self {
899
915
( Included ( ref start) , _) => Included ( start) ,
@@ -912,7 +928,8 @@ impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
912
928
}
913
929
914
930
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
915
- impl < ' a , T : ?Sized + ' a > RangeBounds < T > for ( Bound < & ' a T > , Bound < & ' a T > ) {
931
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
932
+ impl < ' a , T : ?Sized + ' a > const RangeBounds < T > for ( Bound < & ' a T > , Bound < & ' a T > ) {
916
933
fn start_bound ( & self ) -> Bound < & T > {
917
934
self . 0
918
935
}
@@ -923,7 +940,8 @@ impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
923
940
}
924
941
925
942
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
926
- impl < T > RangeBounds < T > for RangeFrom < & T > {
943
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
944
+ impl < T > const RangeBounds < T > for RangeFrom < & T > {
927
945
fn start_bound ( & self ) -> Bound < & T > {
928
946
Included ( self . start )
929
947
}
@@ -933,7 +951,8 @@ impl<T> RangeBounds<T> for RangeFrom<&T> {
933
951
}
934
952
935
953
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
936
- impl < T > RangeBounds < T > for RangeTo < & T > {
954
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
955
+ impl < T > const RangeBounds < T > for RangeTo < & T > {
937
956
fn start_bound ( & self ) -> Bound < & T > {
938
957
Unbounded
939
958
}
@@ -943,7 +962,8 @@ impl<T> RangeBounds<T> for RangeTo<&T> {
943
962
}
944
963
945
964
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
946
- impl < T > RangeBounds < T > for Range < & T > {
965
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
966
+ impl < T > const RangeBounds < T > for Range < & T > {
947
967
fn start_bound ( & self ) -> Bound < & T > {
948
968
Included ( self . start )
949
969
}
@@ -953,7 +973,8 @@ impl<T> RangeBounds<T> for Range<&T> {
953
973
}
954
974
955
975
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
956
- impl < T > RangeBounds < T > for RangeInclusive < & T > {
976
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
977
+ impl < T > const RangeBounds < T > for RangeInclusive < & T > {
957
978
fn start_bound ( & self ) -> Bound < & T > {
958
979
Included ( self . start )
959
980
}
@@ -963,7 +984,8 @@ impl<T> RangeBounds<T> for RangeInclusive<&T> {
963
984
}
964
985
965
986
#[ stable( feature = "collections_range" , since = "1.28.0" ) ]
966
- impl < T > RangeBounds < T > for RangeToInclusive < & T > {
987
+ #[ rustc_const_unstable( feature = "const_range_bounds" , issue = "108082" ) ]
988
+ impl < T > const RangeBounds < T > for RangeToInclusive < & T > {
967
989
fn start_bound ( & self ) -> Bound < & T > {
968
990
Unbounded
969
991
}
0 commit comments