From 36a9243efa67a37b5a690e44234f0ccca74e8209 Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Thu, 2 Dec 2021 21:54:15 +0100 Subject: [PATCH] remove `const_assert!` in favor of std's `assert!` --- src/addr.rs | 4 ++-- src/lib.rs | 14 -------------- src/structures/gdt.rs | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/addr.rs b/src/addr.rs index d796a0e35..b71d7b63d 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -544,7 +544,7 @@ impl Sub for PhysAddr { /// feature, the panic message will be "index out of bounds". #[inline] pub const fn align_down(addr: u64, align: u64) -> u64 { - const_assert!(align.is_power_of_two(), "`align` must be a power of two"); + assert!(align.is_power_of_two(), "`align` must be a power of two"); addr & !(align - 1) } @@ -556,7 +556,7 @@ pub const fn align_down(addr: u64, align: u64) -> u64 { /// feature, the panic message will be "index out of bounds". #[inline] pub const fn align_up(addr: u64, align: u64) -> u64 { - const_assert!(align.is_power_of_two(), "`align` must be a power of two"); + assert!(align.is_power_of_two(), "`align` must be a power of two"); let align_mask = align - 1; if addr & align_mask == 0 { addr // already aligned diff --git a/src/lib.rs b/src/lib.rs index 652dd5130..4a6cda74d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ //! and access to various system registers. #![cfg_attr(not(test), no_std)] -#![cfg_attr(feature = "const_fn", feature(const_panic))] // Better panic messages #![cfg_attr(feature = "const_fn", feature(const_mut_refs))] // GDT add_entry() #![cfg_attr(feature = "const_fn", feature(const_fn_fn_ptr_basics))] // IDT new() #![cfg_attr(feature = "const_fn", feature(const_fn_trait_bound))] // PageSize marker trait @@ -45,19 +44,6 @@ macro_rules! const_fn { }; } -// Helper method for assert! in const fn. Uses out of bounds indexing if an -// assertion fails and the "const_fn" feature is not enabled. -#[cfg(feature = "const_fn")] -macro_rules! const_assert { - ($cond:expr, $($arg:tt)+) => { assert!($cond, $($arg)*) }; -} -#[cfg(not(feature = "const_fn"))] -macro_rules! const_assert { - ($cond:expr, $($arg:tt)+) => { - [(); 1][!($cond as bool) as usize] - }; -} - #[cfg(all(feature = "instructions", feature = "external_asm"))] pub(crate) mod asm; diff --git a/src/structures/gdt.rs b/src/structures/gdt.rs index 4911146a8..6ea977af9 100644 --- a/src/structures/gdt.rs +++ b/src/structures/gdt.rs @@ -72,7 +72,7 @@ impl GlobalDescriptorTable { let mut table = [0; 8]; let mut idx = 0; - const_assert!( + assert!( next_free <= 8, "initializing a GDT from a slice requires it to be **at most** 8 elements." );