Skip to content

Commit

Permalink
Merge pull request #326 from Freax13/const-panic
Browse files Browse the repository at this point in the history
remove `const_assert!` in favor of std's `assert!`
  • Loading branch information
Freax13 authored Dec 5, 2021
2 parents 498fa5c + 36a9243 commit 55d5fad
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ impl Sub<PhysAddr> 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)
}

Expand All @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/structures/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
);
Expand Down

0 comments on commit 55d5fad

Please sign in to comment.