@@ -2569,6 +2569,12 @@ extern "rust-intrinsic" {
2569
2569
#[ rustc_nounwind]
2570
2570
#[ cfg( not( bootstrap) ) ]
2571
2571
pub fn is_val_statically_known < T : Copy > ( arg : T ) -> bool ;
2572
+
2573
+ #[ rustc_const_unstable( feature = "delayed_debug_assertions" , issue = "none" ) ]
2574
+ #[ rustc_safe_intrinsic]
2575
+ #[ rustc_nounwind]
2576
+ #[ cfg( not( bootstrap) ) ]
2577
+ pub ( crate ) fn debug_assertions ( ) -> bool ;
2572
2578
}
2573
2579
2574
2580
// FIXME: Seems using `unstable` here completely ignores `rustc_allow_const_fn_unstable`
@@ -2604,27 +2610,37 @@ pub const unsafe fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
2604
2610
///
2605
2611
/// So in a sense it is UB if this macro is useful, but we expect callers of `unsafe fn` to make
2606
2612
/// the occasional mistake, and this check should help them figure things out.
2607
- #[ allow_internal_unstable( const_eval_select) ] // permit this to be called in stably-const fn
2613
+ #[ allow_internal_unstable( const_eval_select, delayed_debug_assertions ) ] // permit this to be called in stably-const fn
2608
2614
macro_rules! assert_unsafe_precondition {
2609
2615
( $name: expr, $( [ $( $tt: tt) * ] ) ?( $( $i: ident: $ty: ty) ,* $( , ) ?) => $e: expr $( , ) ?) => {
2610
- if cfg!( debug_assertions) {
2611
- // allow non_snake_case to allow capturing const generics
2612
- #[ allow( non_snake_case) ]
2613
- #[ inline( always) ]
2614
- fn runtime$( <$( $tt) * >) ?( $( $i: $ty) ,* ) {
2615
- if !$e {
2616
- // don't unwind to reduce impact on code size
2617
- :: core:: panicking:: panic_nounwind(
2618
- concat!( "unsafe precondition(s) violated: " , $name)
2619
- ) ;
2620
- }
2616
+ {
2617
+ // allow non_snake_case to allow capturing const generics
2618
+ #[ allow( non_snake_case) ]
2619
+ #[ inline( always) ]
2620
+ fn runtime$( <$( $tt) * >) ?( $( $i: $ty) ,* ) {
2621
+ #[ cfg( miri) ]
2622
+ return ;
2623
+ if !$e {
2624
+ // don't unwind to reduce impact on code size
2625
+ :: core:: panicking:: panic_nounwind(
2626
+ concat!( "unsafe precondition(s) violated: " , $name)
2627
+ ) ;
2621
2628
}
2622
- #[ allow( non_snake_case) ]
2623
- #[ inline]
2624
- const fn comptime$( <$( $tt) * >) ?( $( _: $ty) ,* ) { }
2629
+ }
2630
+ #[ allow( non_snake_case) ]
2631
+ #[ inline]
2632
+ const fn comptime$( <$( $tt) * >) ?( $( _: $ty) ,* ) { }
2625
2633
2634
+ #[ cfg( bootstrap) ]
2635
+ if cfg!( debug_assertions) {
2626
2636
:: core:: intrinsics:: const_eval_select( ( $( $i, ) * ) , comptime, runtime) ;
2627
2637
}
2638
+
2639
+ #[ cfg( not( bootstrap) ) ]
2640
+ if :: core:: intrinsics:: debug_assertions( ) {
2641
+ :: core:: intrinsics:: const_eval_select( ( $( $i, ) * ) , comptime, runtime) ;
2642
+ }
2643
+ }
2628
2644
} ;
2629
2645
}
2630
2646
pub ( crate ) use assert_unsafe_precondition;
@@ -2633,19 +2649,20 @@ pub(crate) use assert_unsafe_precondition;
2633
2649
/// `align_of::<T>()`.
2634
2650
#[ inline]
2635
2651
pub ( crate ) fn is_aligned_and_not_null < T > ( ptr : * const T ) -> bool {
2636
- ! ptr. is_null ( ) && ptr. is_aligned ( )
2652
+ ( ( ptr. addr ( ) & const { crate :: mem :: align_of :: < T > ( ) - 1 } ) == 0 ) & ( ptr. addr ( ) != 0 )
2637
2653
}
2638
2654
2655
+ /*
2639
2656
/// Checks whether an allocation of `len` instances of `T` exceeds
2640
2657
/// the maximum allowed allocation size.
2641
2658
#[inline]
2642
2659
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
2643
- let max_len = const {
2660
+ len < = const {
2644
2661
let size = crate::mem::size_of::<T>();
2645
2662
if size == 0 { usize::MAX } else { isize::MAX as usize / size }
2646
2663
};
2647
- len <= max_len
2648
2664
}
2665
+ */
2649
2666
2650
2667
/// Checks whether the regions of memory starting at `src` and `dst` of size
2651
2668
/// `count * size_of::<T>()` do *not* overlap.
@@ -2763,6 +2780,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
2763
2780
// SAFETY: the safety contract for `copy_nonoverlapping` must be
2764
2781
// upheld by the caller.
2765
2782
unsafe {
2783
+ /*
2766
2784
assert_unsafe_precondition!(
2767
2785
"ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
2768
2786
and the specified memory ranges do not overlap",
@@ -2771,6 +2789,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
2771
2789
&& is_aligned_and_not_null(dst)
2772
2790
&& is_nonoverlapping(src, dst, count)
2773
2791
);
2792
+ */
2774
2793
copy_nonoverlapping ( src, dst, count)
2775
2794
}
2776
2795
}
@@ -2858,11 +2877,13 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2858
2877
2859
2878
// SAFETY: the safety contract for `copy` must be upheld by the caller.
2860
2879
unsafe {
2880
+ /*
2861
2881
assert_unsafe_precondition!(
2862
2882
"ptr::copy requires that both pointer arguments are aligned and non-null",
2863
2883
[T](src: *const T, dst: *mut T) =>
2864
2884
is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)
2865
2885
);
2886
+ */
2866
2887
copy ( src, dst, count)
2867
2888
}
2868
2889
}
0 commit comments