Skip to content

Commit

Permalink
fix(no_std): fix compilation error in unreachable_unchecked
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Apr 11, 2022
1 parent 8ae178a commit cbf943a
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,32 @@ macro_rules! fmt_bits {

#[allow(unused_macros)]
macro_rules! unreachable_unchecked {
($($arg:tt)+) => {
crate::unreachable_unchecked!(@inner , format_args!(": {}", format_args!($($arg)*)))
(@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();
}

}
};

() => {
crate::unreachable_unchecked!(@inner ".")
($($arg:tt)+) => {
unreachable_unchecked!(@inner format_args!(": {}", format_args!($($arg)*)))
};

(@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();
}
() => {
unreachable_unchecked!(@inner ".")
};
}

0 comments on commit cbf943a

Please sign in to comment.