@@ -79,16 +79,6 @@ pub use index::check_range;
79
79
#[ lang = "slice" ]
80
80
#[ cfg( not( test) ) ]
81
81
impl < 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
-
92
82
/// Returns the number of elements in the slice.
93
83
///
94
84
/// # Examples
@@ -101,20 +91,11 @@ impl<T> [T] {
101
91
#[ rustc_const_stable( feature = "const_slice_len" , since = "1.32.0" ) ]
102
92
#[ inline]
103
93
// 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) ]
105
95
pub const fn len ( & self ) -> usize {
106
96
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
107
97
// 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 }
118
99
}
119
100
120
101
/// Returns `true` if the slice has a length of 0.
0 commit comments