@@ -705,35 +705,6 @@ pub trait RangeBounds<T: ?Sized> {
705705 #[ stable( feature = "collections_range" , since = "1.28.0" ) ]
706706 fn end_bound ( & self ) -> Bound < & T > ;
707707
708- /// Returns `true` if `item` is contained in the range.
709- ///
710- /// # Examples
711- ///
712- /// ```
713- /// assert!( (3..5).contains(&4));
714- /// assert!(!(3..5).contains(&2));
715- ///
716- /// assert!( (0.0..1.0).contains(&0.5));
717- /// assert!(!(0.0..1.0).contains(&f32::NAN));
718- /// assert!(!(0.0..f32::NAN).contains(&0.5));
719- /// assert!(!(f32::NAN..1.0).contains(&0.5));
720- #[ stable( feature = "range_contains" , since = "1.35.0" ) ]
721- fn contains < U > ( & self , item : & U ) -> bool
722- where
723- T : PartialOrd < U > ,
724- U : ?Sized + PartialOrd < T > ,
725- {
726- ( match self . start_bound ( ) {
727- Included ( ref start) => * start <= item,
728- Excluded ( ref start) => * start < item,
729- Unbounded => true ,
730- } ) && ( match self . end_bound ( ) {
731- Included ( ref end) => item <= * end,
732- Excluded ( ref end) => item < * end,
733- Unbounded => true ,
734- } )
735- }
736-
737708 /// Performs bounds-checking of this range.
738709 ///
739710 /// The returned [`Range`] is safe to pass to [`slice::get_unchecked`] and
@@ -749,46 +720,46 @@ pub trait RangeBounds<T: ?Sized> {
749720 /// # Examples
750721 ///
751722 /// ```
752- /// #![feature(range_bounds_for_length )]
723+ /// #![feature(range_bounds_assert_len )]
753724 ///
754725 /// use std::ops::RangeBounds;
755726 ///
756727 /// let v = [10, 40, 30];
757- /// assert_eq!(1..2, (1..2).for_length (v.len()));
758- /// assert_eq!(0..2, (..2).for_length (v.len()));
759- /// assert_eq!(1..3, (1..).for_length (v.len()));
728+ /// assert_eq!(1..2, (1..2).assert_len (v.len()));
729+ /// assert_eq!(0..2, (..2).assert_len (v.len()));
730+ /// assert_eq!(1..3, (1..).assert_len (v.len()));
760731 /// ```
761732 ///
762733 /// Panics when [`Index::index`] would panic:
763734 ///
764735 /// ```should_panic
765- /// #![feature(range_bounds_for_length )]
736+ /// #![feature(range_bounds_assert_len )]
766737 ///
767738 /// use std::ops::RangeBounds;
768739 ///
769- /// (2..1).for_length (3);
740+ /// (2..1).assert_len (3);
770741 /// ```
771742 ///
772743 /// ```should_panic
773- /// #![feature(range_bounds_for_length )]
744+ /// #![feature(range_bounds_assert_len )]
774745 ///
775746 /// use std::ops::RangeBounds;
776747 ///
777- /// (1..4).for_length (3);
748+ /// (1..4).assert_len (3);
778749 /// ```
779750 ///
780751 /// ```should_panic
781- /// #![feature(range_bounds_for_length )]
752+ /// #![feature(range_bounds_assert_len )]
782753 ///
783754 /// use std::ops::RangeBounds;
784755 ///
785- /// (1..=usize::MAX).for_length (3);
756+ /// (1..=usize::MAX).assert_len (3);
786757 /// ```
787758 ///
788759 /// [`Index::index`]: crate::ops::Index::index
789760 #[ track_caller]
790- #[ unstable( feature = "range_bounds_for_length " , issue = "76393" ) ]
791- fn for_length ( self , len : usize ) -> Range < usize >
761+ #[ unstable( feature = "range_bounds_assert_len " , issue = "76393" ) ]
762+ fn assert_len ( self , len : usize ) -> Range < usize >
792763 where
793764 Self : RangeBounds < usize > ,
794765 {
@@ -819,6 +790,35 @@ pub trait RangeBounds<T: ?Sized> {
819790
820791 Range { start, end }
821792 }
793+
794+ /// Returns `true` if `item` is contained in the range.
795+ ///
796+ /// # Examples
797+ ///
798+ /// ```
799+ /// assert!( (3..5).contains(&4));
800+ /// assert!(!(3..5).contains(&2));
801+ ///
802+ /// assert!( (0.0..1.0).contains(&0.5));
803+ /// assert!(!(0.0..1.0).contains(&f32::NAN));
804+ /// assert!(!(0.0..f32::NAN).contains(&0.5));
805+ /// assert!(!(f32::NAN..1.0).contains(&0.5));
806+ #[ stable( feature = "range_contains" , since = "1.35.0" ) ]
807+ fn contains < U > ( & self , item : & U ) -> bool
808+ where
809+ T : PartialOrd < U > ,
810+ U : ?Sized + PartialOrd < T > ,
811+ {
812+ ( match self . start_bound ( ) {
813+ Included ( ref start) => * start <= item,
814+ Excluded ( ref start) => * start < item,
815+ Unbounded => true ,
816+ } ) && ( match self . end_bound ( ) {
817+ Included ( ref end) => item <= * end,
818+ Excluded ( ref end) => item < * end,
819+ Unbounded => true ,
820+ } )
821+ }
822822}
823823
824824use self :: Bound :: { Excluded , Included , Unbounded } ;
0 commit comments