diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index ecd7d616d3572..9d8ea515d41a3 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -472,9 +472,12 @@ impl RawVec { // `Layout::array` cannot overflow here because it would have // owerflown earlier when capacity was larger. let new_layout = Layout::array::(amount).unwrap_unchecked(); - self.alloc - .shrink(ptr, layout, new_layout) - .map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })? + // We avoid `map_err` here because it bloats the amount of LLVM IR + // generated. + match self.alloc.shrink(ptr, layout, new_layout) { + Ok(ptr) => ptr, + Err(_) => Err(AllocError { layout: new_layout, non_exhaustive: () })?, + } }; self.set_ptr(ptr); Ok(())