@@ -33,23 +33,17 @@ impl<T> RawVec<T> {
3333 assert! (mem :: size_of :: <T >() != 0 , " capacity overflow" );
3434
3535 let (new_cap , new_layout ) = if self . cap == 0 {
36- (1 , Layout :: array :: <T >(1 ). unwrap () )
36+ (1 , Layout :: array :: <T >(1 ))
3737 } else {
38- // This can't overflow because we ensure self.cap <= isize::MAX.
38+ // This can't overflow since self.cap <= isize::MAX.
3939 let new_cap = 2 * self . cap;
40-
41- // `Layout::array` checks that the number of bytes is <= usize::MAX,
42- // but this is redundant since old_layout.size() <= isize::MAX,
43- // so the `unwrap` should never fail.
44- let new_layout = Layout :: array :: <T >(new_cap ). unwrap ();
45- (new_cap , new_layout )
40+ (new_cap , Layout :: array :: <T >(new_cap ))
4641 };
4742
48- // Ensure that the new allocation doesn't exceed `isize::MAX` bytes.
49- assert! (
50- new_layout . size () <= isize :: MAX as usize ,
51- " Allocation too large"
52- );
43+ // `Layout::array` checks that the number of bytes allocated is
44+ // in 1..=isize::MAX and will error otherwise. An allocation of
45+ // 0 bytes isn't possible thanks to the above condition.
46+ let new_layout = new_layout . expect (" Allocation too large" );
5347
5448 let new_ptr = if self . cap == 0 {
5549 unsafe { alloc :: alloc (new_layout ) }
0 commit comments