Skip to content

Commit

Permalink
fix(no_std): wrong feature gate for println macros
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 73a116c commit 208defc
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
macro_rules! test_println {
($($arg:tt)*) => {
if cfg!(test) || cfg!(all(thingbuf_trace, feature = "std")) {
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 {:>30}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
} else {
crate::loom::traceln(format_args!(
"[{:?} {:>30}:{:<3}] {}",
crate::loom::thread::current().id(),
file!(),
line!(),
format_args!($($arg)*),
));
}
#[cfg(all(feature = "std", any(thingbuf_trace, 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 {:>30}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
} else {
crate::loom::traceln(format_args!(
"[{:?} {:>30}:{:<3}] {}",
crate::loom::thread::current().id(),
file!(),
line!(),
format_args!($($arg)*),
));
}
}
}
Expand All @@ -22,7 +21,7 @@ macro_rules! test_dbg {
($e:expr) => {
match $e {
e => {
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("{} = {:?}", stringify!($e), &e);
e
}
Expand All @@ -40,7 +39,7 @@ macro_rules! assert_dbg {
};
(@$e:expr, $($msg:tt)+) => {
{
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("ASSERT: {}{}", stringify!($e), format_args!($($msg)*));
assert!($e, $($msg)*);
test_println!("-> ok");
Expand All @@ -58,7 +57,7 @@ macro_rules! assert_eq_dbg {
};
(@ $a:expr, $b:expr, $($msg:tt)+) => {
{
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("ASSERT: {} == {}{}", stringify!($a), stringify!($b), format_args!($($msg)*));
assert_eq!($a, $b, $($msg)*);
test_println!("-> ok");
Expand Down

0 comments on commit 208defc

Please sign in to comment.