From cbf943a2801fcb85717251e6a1f9a98ad1ae9299 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 11 Apr 2022 16:34:03 -0700 Subject: [PATCH] fix(no_std): fix compilation error in `unreachable_unchecked` Signed-off-by: Eliza Weisman --- src/macros.rs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 382e568..49ed9ca 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 ".") }; }