@@ -1017,7 +1017,7 @@ impl<T: ?Sized> Box<T> {
10171017 /// resulting `Box`. Specifically, the `Box` destructor will call
10181018 /// the destructor of `T` and free the allocated memory. For this
10191019 /// to be safe, the memory must have been allocated in accordance
1020- /// with the [memory layout] used by `Box` .
1020+ /// with the [memory layout] used by `Box`.
10211021 ///
10221022 /// # Safety
10231023 ///
@@ -1056,8 +1056,19 @@ impl<T: ?Sized> Box<T> {
10561056 #[ stable( feature = "box_raw" , since = "1.4.0" ) ]
10571057 #[ inline]
10581058 #[ must_use = "call `drop(Box::from_raw(ptr))` if you intend to drop the `Box`" ]
1059- pub unsafe fn from_raw ( raw : * mut T ) -> Self {
1060- unsafe { Self :: from_raw_in ( raw, Global ) }
1059+ pub unsafe fn from_raw ( ptr : * mut T ) -> Self {
1060+ core:: assert_unsafe_precondition!(
1061+ check_language_ub,
1062+ "Box::from_raw requires that its pointer argument is properly aligned and not null" ,
1063+ (
1064+ ptr: * const ( ) = ptr as * const ( ) ,
1065+ align: usize = align_of:: <T >( ) ,
1066+ is_zst: bool = T :: IS_ZST ,
1067+ ) => maybe_is_aligned_and_not_null( ptr, align, is_zst)
1068+ ) ;
1069+
1070+ //assert_pointer_is_aligned_and_not_null!("Box::from_raw", ptr, align_of::<T>(), T::IS_ZST);
1071+ unsafe { Self :: from_raw_in ( ptr, Global ) }
10611072 }
10621073
10631074 /// Constructs a box from a `NonNull` pointer.
@@ -1111,6 +1122,12 @@ impl<T: ?Sized> Box<T> {
11111122 #[ inline]
11121123 #[ must_use = "call `drop(Box::from_non_null(ptr))` if you intend to drop the `Box`" ]
11131124 pub unsafe fn from_non_null ( ptr : NonNull < T > ) -> Self {
1125+ /*assert_pointer_is_aligned_and_not_null!(
1126+ "Box::from_non_null",
1127+ ptr,
1128+ align_of::<T>(),
1129+ T::IS_ZST
1130+ );*/
11141131 unsafe { Self :: from_raw ( ptr. as_ptr ( ) ) }
11151132 }
11161133}
@@ -1166,8 +1183,14 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11661183 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
11671184 #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
11681185 #[ inline]
1169- pub const unsafe fn from_raw_in ( raw : * mut T , alloc : A ) -> Self {
1170- Box ( unsafe { Unique :: new_unchecked ( raw) } , alloc)
1186+ pub const unsafe fn from_raw_in ( ptr : * mut T , alloc : A ) -> Self {
1187+ /*assert_pointer_is_aligned_and_not_null!(
1188+ "Box::from_raw_in",
1189+ ptr,
1190+ align_of::<T>(),
1191+ T::IS_ZST
1192+ );*/
1193+ Box ( unsafe { Unique :: new_unchecked ( ptr) } , alloc)
11711194 }
11721195
11731196 /// Constructs a box from a `NonNull` pointer in the given allocator.
0 commit comments