Skip to main content

vstd_extra/
trans_macros.rs

1use vstd::prelude::*;
2
3use crate::panic::*;
4
5/* Verus cannot translate formatting machinery used by `core::panic!`; select the modeled
6 * diverging boundary only while retaining ghost bodies.
7 * Origin Rust: <none; new executable code>
8 */
9#[macro_export]
10macro_rules! panic {
11    ($($arg:tt)*) => {{
12        #[cfg(verus_keep_ghost_body)]
13        {
14            $crate::panic::panic_diverge()
15        }
16        #[cfg(not(verus_keep_ghost_body))]
17        {
18            ::core::panic!($($arg)*)
19        }
20    }};
21}
22
23#[macro_export]
24macro_rules! assert {
25    ($cond:expr) => {
26        if !($cond) {
27            $crate::panic::panic_diverge()
28        }
29    };
30    ($cond:expr, $msg:literal) => {
31        if !($cond) {
32            $crate::panic::panic_diverge()
33        }
34    };
35}
36
37#[macro_export]
38macro_rules! assert_eq {
39    ($l:expr, $r:expr) => {
40        if ($l != $r) {
41            $crate::panic::panic_diverge()
42        }
43    };
44}
45
46#[macro_export]
47macro_rules! debug_assert {
48    ($cond:expr) => {
49        #[cfg(debug_assertions)]
50        if !($cond) {
51            $crate::panic::panic_diverge()
52        }
53    };
54    ($cond:expr, $msg:literal) => {
55        #[cfg(debug_assertions)]
56        if !($cond) {
57            $crate::panic::panic_diverge()
58        }
59    };
60}
61
62#[macro_export]
63macro_rules! debug_assert_eq {
64    ($l:expr, $r:expr) => {
65        #[cfg(debug_assertions)]
66        if ($l != $r) {
67            $crate::panic::panic_diverge()
68        }
69    };
70}