Skip to content

Commit

Permalink
rust can now assert!() in const context
Browse files Browse the repository at this point in the history
  • Loading branch information
dholroyd committed Dec 3, 2022
1 parent cb957e5 commit 8145223
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms, future_incompatible, missing_docs)]

// until we have https://github.com/rust-lang/rust/issues/51999 I think
macro_rules! const_assert {
($x:expr $(,)?) => {
#[allow(unknown_lints, clippy::eq_op)]
{
const ASSERT: [(); 1] = [()];
let _ = ASSERT[!($x) as usize];
}
};
}

pub mod packet;
#[macro_use]
pub mod demultiplex;
Expand Down
2 changes: 1 addition & 1 deletion src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl Pid {

/// Panics if the given value is greater than `Pid::MAX_VALUE`.
pub const fn new(pid: u16) -> Pid {
const_assert!(pid <= 0x1fff);
assert!(pid <= 0x1fff);
Pid(pid)
}
}
Expand Down

0 comments on commit 8145223

Please sign in to comment.