diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 817b93720ce28..affbd754dc9b3 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -292,6 +292,11 @@ impl RawVec { if self.needs_to_grow(len, additional) { do_reserve_and_handle(self, len, additional); } + + unsafe { + // Inform the optimizer that the reservation has succeeded or wasn't needed + core::intrinsics::assume(!self.needs_to_grow(len, additional)); + } } /// A specialized version of `reserve()` used only by the hot and diff --git a/tests/ui/hygiene/panic-location.run.stderr b/tests/ui/hygiene/panic-location.run.stderr index e0dc13c0c95c8..cee00a23c5ee8 100644 --- a/tests/ui/hygiene/panic-location.run.stderr +++ b/tests/ui/hygiene/panic-location.run.stderr @@ -1,3 +1,3 @@ -thread 'main' panicked at library/alloc/src/raw_vec.rs:545:5: +thread 'main' panicked at library/alloc/src/raw_vec.rs:550:5: capacity overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace