@@ -531,21 +531,25 @@ impl Sub<PhysAddr> for PhysAddr {
531
531
532
532
/// Align address downwards.
533
533
///
534
- /// Returns the greatest x with alignment `align` so that x <= addr. The alignment must be
535
- /// a power of 2.
534
+ /// Returns the greatest `x` with alignment `align` so that `x <= addr`.
535
+ ///
536
+ /// Panics if the alignment is not a power of two. Without the `const_fn`
537
+ /// feature, the panic message will be "index out of bounds".
536
538
#[ inline]
537
- pub fn align_down ( addr : u64 , align : u64 ) -> u64 {
538
- assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
539
+ pub const fn align_down ( addr : u64 , align : u64 ) -> u64 {
540
+ const_assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
539
541
addr & !( align - 1 )
540
542
}
541
543
542
544
/// Align address upwards.
543
545
///
544
- /// Returns the smallest x with alignment `align` so that x >= addr. The alignment must be
545
- /// a power of 2.
546
+ /// Returns the smallest `x` with alignment `align` so that `x >= addr`.
547
+ ///
548
+ /// Panics if the alignment is not a power of two. Without the `const_fn`
549
+ /// feature, the panic message will be "index out of bounds".
546
550
#[ inline]
547
- pub fn align_up ( addr : u64 , align : u64 ) -> u64 {
548
- assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
551
+ pub const fn align_up ( addr : u64 , align : u64 ) -> u64 {
552
+ const_assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
549
553
let align_mask = align - 1 ;
550
554
if addr & align_mask == 0 {
551
555
addr // already aligned
0 commit comments