@@ -2614,29 +2614,30 @@ pub const unsafe fn is_val_statically_known<T: Copy>(_arg: T) -> bool {
2614
2614
macro_rules! assert_unsafe_precondition {
2615
2615
( $name: expr, $( [ $( $tt: tt) * ] ) ?( $( $i: ident: $ty: ty) ,* $( , ) ?) => $e: expr $( , ) ?) => {
2616
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
+ ) ;
2628
+ }
2629
+ }
2630
+ #[ allow( non_snake_case) ]
2631
+ #[ inline]
2632
+ const fn comptime$( <$( $tt) * >) ?( $( _: $ty) ,* ) { }
2633
+
2617
2634
#[ cfg( bootstrap) ]
2618
- let should_check = cfg!( debug_assertions) ;
2635
+ if cfg!( debug_assertions) {
2636
+ :: core:: intrinsics:: const_eval_select( ( $( $i, ) * ) , comptime, runtime) ;
2637
+ }
2619
2638
2620
- // Turn assertions off in Miri, but otherwise check in codegen
2621
2639
#[ cfg( not( bootstrap) ) ]
2622
- let should_check = !cfg!( miri) && :: core:: intrinsics:: debug_assertions( ) ;
2623
-
2624
- if should_check {
2625
- // allow non_snake_case to allow capturing const generics
2626
- #[ allow( non_snake_case) ]
2627
- #[ inline( always) ]
2628
- fn runtime$( <$( $tt) * >) ?( $( $i: $ty) ,* ) {
2629
- if !$e {
2630
- // don't unwind to reduce impact on code size
2631
- :: core:: panicking:: panic_nounwind(
2632
- concat!( "unsafe precondition(s) violated: " , $name)
2633
- ) ;
2634
- }
2635
- }
2636
- #[ allow( non_snake_case) ]
2637
- #[ inline]
2638
- const fn comptime$( <$( $tt) * >) ?( $( _: $ty) ,* ) { }
2639
-
2640
+ if :: core:: intrinsics:: debug_assertions( ) {
2640
2641
:: core:: intrinsics:: const_eval_select( ( $( $i, ) * ) , comptime, runtime) ;
2641
2642
}
2642
2643
}
@@ -2648,22 +2649,18 @@ pub(crate) use assert_unsafe_precondition;
2648
2649
/// `align_of::<T>()`.
2649
2650
#[ inline]
2650
2651
pub ( crate ) fn is_aligned_and_not_null < T > ( ptr : * const T ) -> bool {
2651
- let mask = const { crate :: mem:: align_of :: < T > ( ) - 1 } ;
2652
- let is_aligned = ( ptr. addr ( ) & mask) == 0 ;
2653
- let not_null = ptr. addr ( ) != 0 ;
2654
- is_aligned && not_null
2652
+ ( ( ptr. addr ( ) & const { crate :: mem:: align_of :: < T > ( ) - 1 } ) == 0 ) & ( ptr. addr ( ) != 0 )
2655
2653
}
2656
2654
2657
2655
/*
2658
2656
/// Checks whether an allocation of `len` instances of `T` exceeds
2659
2657
/// the maximum allowed allocation size.
2660
2658
#[inline]
2661
2659
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
2662
- let max_len = const {
2660
+ len < = const {
2663
2661
let size = crate::mem::size_of::<T>();
2664
2662
if size == 0 { usize::MAX } else { isize::MAX as usize / size }
2665
2663
};
2666
- len <= max_len
2667
2664
}
2668
2665
*/
2669
2666
0 commit comments