From 3064132821a3ad6ac02a5fd4f647f702a053ecaa Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 28 Jan 2022 14:47:26 +0100 Subject: [PATCH] Improve and simplify token handling in macros The standard library macros also use a `$($foo:tt)*` for this, so we should probably too. Since eprinln!() already handles trailing commas we don't need to do any special handling, and this fixes parsing with complex expressions as arguments. --- src/debug.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 1d24e76f..40368b83 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -22,8 +22,8 @@ /// allocations. #[macro_export] macro_rules! nih_log { - ($format:expr $(, $arg:tt)* $(,)?) => ( - eprintln!(concat!("[", file!(), ":", line!(), "] ", $format), $($arg)*) + ($format:expr $(, $($args:tt)*)?) => ( + eprintln!(concat!("[", file!(), ":", line!(), "] ", $format), $($($args)*)?) ); } @@ -38,9 +38,9 @@ macro_rules! nih_debug_assert { nih_log!(concat!("Debug assertion failed: ", stringify!($cond))); } ); - ($cond:expr, $format:expr $(, $arg:tt)* $(,)?) => ( + ($cond:expr, $format:expr $(, $($args:tt)*)?) => ( if cfg!(debug_assertions) && !$cond { - nih_log!(concat!("Debug assertion failed: ", stringify!($cond), ", ", $format) $(, $arg)*); + nih_log!(concat!("Debug assertion failed: ", stringify!($cond), ", ", $format), $($($args)*)?); } ); } @@ -54,9 +54,9 @@ macro_rules! nih_debug_assert_failure { nih_log!("Debug assertion failed"); } ); - ($format:expr $(, $arg:tt)* $(,)?) => ( + ($format:expr $(, $($args:tt)*)?) => ( if cfg!(debug_assertions) { - nih_log!(concat!("Debug assertion failed: ", $format) $(, $arg)*); + nih_log!(concat!("Debug assertion failed: ", $format), $($($args)*)?); } ); } @@ -70,9 +70,9 @@ macro_rules! nih_debug_assert_eq { nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right))); } ); - (left:expr, $right:expr, $format:expr $(, $arg:tt)* $(,)?) => ( + (left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => ( if cfg!(debug_assertions) && $left != $right { - nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format) $(, $arg)*); + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " != ", stringify!($right), ", ", $format), $($($args)*)?); } ); } @@ -86,9 +86,9 @@ macro_rules! nih_debug_assert_neq { nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right))); } ); - (left:expr, $right:expr, $format:expr $(, $arg:tt)* $(,)?) => ( + (left:expr, $right:expr, $format:expr $(, $($args:tt)*)?) => ( if cfg!(debug_assertions) && $left == $right { - nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format) $(, $arg)*); + nih_log!(concat!("Debug assertion failed: ", stringify!($left), " == ", stringify!($right), ", ", $format), $($($args)*)?); } ); }