1macro_rules! test_println {
2 ($($arg:tt)*) => {
3 if cfg!(test) && cfg!(slab_print) {
4 if std::thread::panicking() {
5 // getting the thread ID while panicking doesn't seem to play super nicely with loom's
6 // mock lazy_static...
7 println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
8 } else {
9 println!("[{:?} {:>17}:{:<3}] {}", crate::Tid::<crate::DefaultConfig>::current(), file!(), line!(), format_args!($($arg)*))
10 }
11 }
12 }
13}
14
15#[cfg(all(test, loom))]
16macro_rules! test_dbg {
17 ($e:expr) => {
18 match $e {
19 e => {
20 test_println!("{} = {:?}", stringify!($e), &e);
21 e
22 }
23 }
24 };
25}
26
27macro_rules! panic_in_drop {
28 ($($arg:tt)*) => {
29 if !std::thread::panicking() {
30 panic!($($arg)*)
31 } else {
32 let thread = std::thread::current();
33 eprintln!(
34 "thread '{thread}' attempted to panic at '{msg}', {file}:{line}:{col}\n\
35 note: we were already unwinding due to a previous panic.",
36 thread = thread.name().unwrap_or("<unnamed>"),
37 msg = format_args!($($arg)*),
38 file = file!(),
39 line = line!(),
40 col = column!(),
41 );
42 }
43 }
44}
45
46macro_rules! debug_assert_eq_in_drop {
47 ($this:expr, $that:expr) => {
48 debug_assert_eq_in_drop!(@inner $this, $that, "")
49 };
50 ($this:expr, $that:expr, $($arg:tt)+) => {
51 debug_assert_eq_in_drop!(@inner $this, $that, format_args!(": {}", format_args!($($arg)+)))
52 };
53 (@inner $this:expr, $that:expr, $msg:expr) => {
54 if cfg!(debug_assertions) {
55 if $this != $that {
56 panic_in_drop!(
57 "assertion failed ({} == {})\n left: `{:?}`,\n right: `{:?}`{}",
58 stringify!($this),
59 stringify!($that),
60 $this,
61 $that,
62 $msg,
63 )
64 }
65 }
66 }
67}
68