/
macros.rs
67 lines (62 loc) · 1.87 KB
/
macros.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
macro_rules! test_println {
($($arg:tt)*) => {
if cfg!(test) {
if crate::util::panic::panicking() {
// getting the thread ID while panicking doesn't seem to play super nicely with loom's
// mock lazy_static...
println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
} else {
println!("[{:?} {:>17}:{:<3}] {}", crate::loom::thread::current().id(), file!(), line!(), format_args!($($arg)*))
}
}
}
}
macro_rules! test_dbg {
($e:expr) => {
match $e {
e => {
#[cfg(test)]
test_println!("{} = {:?}", stringify!($e), &e);
e
}
}
};
}
macro_rules! feature {
(
#![$meta:meta]
$($item:item)*
) => {
$(
#[cfg($meta)]
#[cfg_attr(docsrs, doc(cfg($meta)))]
$item
)*
}
}
#[allow(unused_macros)]
macro_rules! unreachable_unchecked {
($($arg:tt)+) => {
crate::unreachable_unchecked!(@inner , format_args!(": {}", format_args!($($arg)*)))
};
() => {
crate::unreachable_unchecked!(@inner ".")
};
(@inner $msg:expr) => {
#[cfg(debug_assertions)] {
panic!(
"internal error: entered unreachable code{}\n\n\
/!\\ EXTREMELY SERIOUS WARNING /!\\\n
This code should NEVER be entered; in release mode, this would \
have been an `unreachable_unchecked` hint. The fact that this \
occurred means something VERY bad is going on. \n\
Please contact the `thingbuf` maintainers immediately. Sorry!",
$msg,
);
}
#[cfg(not(debug_assertions))]
unsafe {
core::hint::unreachable_unchecked();
}
};
}