@@ -531,21 +531,25 @@ impl Sub<PhysAddr> for PhysAddr {
531531
532532/// Align address downwards.
533533///
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".
536538#[ 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" ) ;
539541 addr & !( align - 1 )
540542}
541543
542544/// Align address upwards.
543545///
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".
546550#[ 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" ) ;
549553 let align_mask = align - 1 ;
550554 if addr & align_mask == 0 {
551555 addr // already aligned
0 commit comments