@@ -64,7 +64,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
6464use  core:: ops:: { self ,  Index ,  IndexMut ,  Range ,  RangeBounds } ; 
6565use  core:: ptr:: { self ,  NonNull } ; 
6666use  core:: slice:: { self ,  SliceIndex } ; 
67- use  core:: { fmt,  intrinsics} ; 
67+ use  core:: { fmt,  intrinsics,  ub_checks } ; 
6868
6969#[ stable( feature = "extract_if" ,  since = "1.87.0" ) ]  
7070pub  use  self :: extract_if:: ExtractIf ; 
@@ -1058,6 +1058,11 @@ impl<T, A: Allocator> Vec<T, A> {
10581058#[ inline]  
10591059    #[ unstable( feature = "allocator_api" ,  issue = "32838" ) ]  
10601060    pub  unsafe  fn  from_raw_parts_in ( ptr :  * mut  T ,  length :  usize ,  capacity :  usize ,  alloc :  A )  -> Self  { 
1061+         ub_checks:: assert_unsafe_precondition!( 
1062+             check_library_ub, 
1063+             "Vec::from_raw_parts_in requires that length <= capacity" , 
1064+             ( length:  usize  = length,  capacity:  usize  = capacity)  => length <= capacity
1065+         ) ; 
10611066        unsafe  {  Vec  {  buf :  RawVec :: from_raw_parts_in ( ptr,  capacity,  alloc) ,  len :  length }  } 
10621067    } 
10631068
@@ -1174,6 +1179,11 @@ impl<T, A: Allocator> Vec<T, A> {
11741179    #[ unstable( feature = "allocator_api" ,  reason = "new API" ,  issue = "32838" ) ]  
11751180    // #[unstable(feature = "box_vec_non_null", issue = "130364")] 
11761181    pub  unsafe  fn  from_parts_in ( ptr :  NonNull < T > ,  length :  usize ,  capacity :  usize ,  alloc :  A )  -> Self  { 
1182+         ub_checks:: assert_unsafe_precondition!( 
1183+             check_library_ub, 
1184+             "Vec::from_parts_in requires that length <= capacity" , 
1185+             ( length:  usize  = length,  capacity:  usize  = capacity)  => length <= capacity
1186+         ) ; 
11771187        unsafe  {  Vec  {  buf :  RawVec :: from_nonnull_in ( ptr,  capacity,  alloc) ,  len :  length }  } 
11781188    } 
11791189
@@ -1950,7 +1960,11 @@ impl<T, A: Allocator> Vec<T, A> {
19501960#[ inline]  
19511961    #[ stable( feature = "rust1" ,  since = "1.0.0" ) ]  
19521962    pub  unsafe  fn  set_len ( & mut  self ,  new_len :  usize )  { 
1953-         debug_assert ! ( new_len <= self . capacity( ) ) ; 
1963+         ub_checks:: assert_unsafe_precondition!( 
1964+             check_library_ub, 
1965+             "Vec::set_len requires that new_len <= capacity()" , 
1966+             ( new_len:  usize  = new_len,  capacity:  usize  = self . capacity( ) )  => new_len <= capacity
1967+         ) ; 
19541968
19551969        self . len  = new_len; 
19561970    } 
@@ -3695,7 +3709,7 @@ impl<T, A: Allocator> Vec<T, A> {
36953709/// This is optimal if: 
36963710/// 
36973711/// * The tail (elements in the vector after `range`) is empty, 
3698- /// * or `replace_with` yields fewer or equal elements than `range`’ s length 
3712+ /// * or `replace_with` yields fewer or equal elements than `range`' s length 
36993713/// * or the lower bound of its `size_hint()` is exact. 
37003714/// 
37013715/// Otherwise, a temporary vector is allocated and the tail is moved twice. 
0 commit comments