gecs/
util.rs

1#![allow(dead_code)]
2#![allow(unused_macros)]
3#![allow(unused_imports)]
4
5pub(crate) struct NumAssert<const L: usize, const R: usize>;
6
7#[allow(clippy::erasing_op)]
8impl<const L: usize, const R: usize> NumAssert<L, R> {
9    pub const LEQ: usize = R - L;
10    pub const LT: usize = R - L - 1;
11}
12
13macro_rules! num_assert_leq {
14    ($a:expr, $b:expr) => {
15        #[allow(path_statements)]
16        #[allow(clippy::no_effect)]
17        {
18            $crate::util::NumAssert::<{ $a }, { $b }>::LEQ;
19        }
20    };
21}
22
23macro_rules! num_assert_lt {
24    ($a:expr, $b:expr) => {
25        #[allow(path_statements)]
26        #[allow(clippy::no_effect)]
27        {
28            $crate::util::NumAssert::<{ $a }, { $b }>::LT;
29        }
30    };
31}
32
33pub(crate) use num_assert_leq;
34pub(crate) use num_assert_lt;
35
36/// Hints the compiler that the given predicate will always be true.
37///
38/// # Safety
39///
40/// If the given predicate is ever not true, this will result in UB.
41/// This is checked only in builds with debug assertions enabled.
42macro_rules! debug_checked_assume {
43    ($ex:expr) => {
44        if (!$ex) {
45            debug_assert!(false);
46            ::std::hint::unreachable_unchecked();
47        }
48    };
49}
50
51/// Hints the compiler that the given line of code can never be reached.
52///
53/// # Safety
54///
55/// If this line of code is ever reached, this will result in UB.
56/// This is checked only in builds with debug assertions enabled.
57macro_rules! debug_checked_unreachable {
58    () => {
59        debug_assert!(false);
60        ::std::hint::unreachable_unchecked();
61    };
62}
63
64pub(crate) use debug_checked_assume;
65pub(crate) use debug_checked_unreachable;