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
/// Indicates unreachable code that we are confident is *truly* unreachable.
///
/// This is essentially a compromise between `core::unreachable!()` and
/// `core::hint::unreachable_unchecked()`. In debug mode builds and in tests,
/// this expands to `unreachable!()`, causing a panic. However, in release mode
/// non-test builds, this expands to `unreachable_unchecked`. Thus, this is a
/// somewhat safer form of `unreachable_unchecked` that will allow cases where
/// `unreachable_unchecked` would be invalid to be detected early.
///
/// Nonetheless, this must still be used with caution! If code is not adequately
/// tested, it is entirely possible for the `unreachable_unchecked` to be
/// reached in a scenario that was not reachable in tests.
#[macro_export]
macro_rules! unreachable_unchecked {
() => ({
#[cfg(any(test, debug_assertions))]
panic!(
"internal error: entered unreachable code \n\",
/!\\ EXTREMELY SERIOUS WARNING: in release mode, this would have been \n\
\x32 `unreachable_unchecked`! This could result in undefine behavior. \n\
\x32 Please double- or triple-check any assumptions about code which \n\
\x32 could lead to this being triggered."
);
#[allow(unreachable_code)] // lol
{
core::hint::unreachable_unchecked();
}
});
($msg:expr) => ({
$crate::unreachable_unchecked!("{}", $msg)
});
($msg:expr,) => ({
$crate::unreachable_unchecked!($msg)
});
($fmt:expr, $($arg:tt)*) => ({
#[cfg(any(test, debug_assertions))]
panic!(
concat!(
"internal error: entered unreachable code: ",
$fmt,
"\n/!\\ EXTREMELY SERIOUS WARNING: in release mode, this would have been \n\
\x32 `unreachable_unchecked`! This could result in undefine behavior. \n\
\x32 Please double- or triple-check any assumptions about code which \n\
\x32 could lead to this being triggered."
),
$($arg)*
);
#[allow(unreachable_code)] // lol
{
core::hint::unreachable_unchecked();
}
});
}
#[cfg(all(test, not(loom)))]
macro_rules! test_info {
($($arg:tt)+) => {
tracing::trace!($($arg)+);
};
}
#[cfg(all(test, loom))]
macro_rules! test_info {
($($arg:tt)+) => {
tracing_01::trace!($($arg)+);
};
}