diff options
| author | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-07-13 16:06:53 +0800 |
|---|---|---|
| committer | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-07-13 16:06:53 +0800 |
| commit | 1cab09ed9c582e7804bd0f9a6ead61129bb537d5 (patch) | |
| tree | d4a6bbf9ea5a7f6533b1e88f39514b9629004120 /library/alloc/src/vec/mod.rs | |
| parent | 10866f46172e92a7949dca2e5a52b8c444a5b082 (diff) | |
| download | rust-1cab09ed9c582e7804bd0f9a6ead61129bb537d5.tar.gz rust-1cab09ed9c582e7804bd0f9a6ead61129bb537d5.zip | |
`std::vec`: Upgrade `debug_assert` to UB check in `set_len`
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a4741f30fa5..da3d3596d19 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -64,7 +64,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr::{self, NonNull}; use core::slice::{self, SliceIndex}; -use core::{fmt, intrinsics}; +use core::{fmt, intrinsics, ub_checks}; #[stable(feature = "extract_if", since = "1.87.0")] pub use self::extract_if::ExtractIf; @@ -1950,7 +1950,11 @@ impl<T, A: Allocator> Vec<T, A> { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn set_len(&mut self, new_len: usize) { - debug_assert!(new_len <= self.capacity()); + ub_checks::assert_unsafe_precondition!( + check_library_ub, + "Vec::set_len requires that new_len <= capacity()", + (new_len: usize = new_len, capacity: usize = self.capacity()) => new_len <= capacity + ); self.len = new_len; } |
