@@ -79,16 +79,6 @@ pub use index::check_range;
7979#[ lang = "slice" ]
8080#[ cfg( not( test) ) ]
8181impl < T > [ T ] {
82- /// The maximum, inclusive, length such that the slice is no larger than `isize::MAX` bytes.
83- /// This constant is used in `len` below.
84- const MAX_LEN_BOUND : usize = {
85- if mem:: size_of :: < T > ( ) == 0 {
86- usize:: MAX
87- } else {
88- isize:: MAX as usize / mem:: size_of :: < T > ( )
89- }
90- } ;
91-
9282 /// Returns the number of elements in the slice.
9383 ///
9484 /// # Examples
@@ -101,20 +91,11 @@ impl<T> [T] {
10191 #[ rustc_const_stable( feature = "const_slice_len" , since = "1.32.0" ) ]
10292 #[ inline]
10393 // SAFETY: const sound because we transmute out the length field as a usize (which it must be)
104- #[ allow_internal_unstable( const_fn_union, const_assume ) ]
94+ #[ allow_internal_unstable( const_fn_union) ]
10595 pub const fn len ( & self ) -> usize {
10696 // SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
10797 // Only `std` can make this guarantee.
108- let raw_len = unsafe { crate :: ptr:: Repr { rust : self } . raw . len } ;
109-
110- // SAFETY: this assume asserts that `raw_len * size_of::<T>() <= isize::MAX`. All
111- // references must point to one allocation with size at most isize::MAX. Note that we the
112- // multiplication could appear to overflow until we have assumed the bound. This overflow
113- // would make additional values appear 'valid' and then `n > 1` the range of permissible
114- // length would no longer be the full or even a single range.
115- unsafe { crate :: intrinsics:: assume ( raw_len <= Self :: MAX_LEN_BOUND ) } ;
116-
117- raw_len
98+ unsafe { crate :: ptr:: Repr { rust : self } . raw . len }
11899 }
119100
120101 /// Returns `true` if the slice has a length of 0.
0 commit comments