Skip to content

Commit 2bbaebb

Browse files
committed
const_fn: Use const_assert helper macro
Signed-off-by: Joe Richey <[email protected]>
1 parent e501dea commit 2bbaebb

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/addr.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,7 @@ impl Sub<PhysAddr> for PhysAddr {
535535
/// a power of 2.
536536
#[inline]
537537
pub const fn align_down(addr: u64, align: u64) -> u64 {
538-
#[cfg(feature = "const_fn")]
539-
assert!(align.is_power_of_two(), "`align` must be a power of two");
540-
#[cfg(not(feature = "const_fn"))]
541-
[(); 1][!align.is_power_of_two() as usize];
542-
538+
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
543539
addr & !(align - 1)
544540
}
545541

@@ -549,11 +545,7 @@ pub const fn align_down(addr: u64, align: u64) -> u64 {
549545
/// a power of 2.
550546
#[inline]
551547
pub const fn align_up(addr: u64, align: u64) -> u64 {
552-
#[cfg(feature = "const_fn")]
553-
assert!(align.is_power_of_two(), "`align` must be a power of two");
554-
#[cfg(not(feature = "const_fn"))]
555-
[(); 1][!align.is_power_of_two() as usize];
556-
548+
const_assert!(align.is_power_of_two(), "`align` must be a power of two");
557549
let align_mask = align - 1;
558550
if addr & align_mask == 0 {
559551
addr // already aligned

src/structures/gdt.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@ impl GlobalDescriptorTable {
117117
let mut table = [0; 8];
118118
let mut idx = 0;
119119

120-
#[cfg(feature = "const_fn")]
121-
assert!(
120+
const_assert!(
122121
next_free <= 8,
123122
"initializing a GDT from a slice requires it to be **at most** 8 elements."
124123
);
125-
#[cfg(not(feature = "const_fn"))]
126-
[(); 1][!(next_free <= 8) as usize];
127124

128125
while idx != next_free {
129126
table[idx] = slice[idx];

0 commit comments

Comments
 (0)