From 1a7ffda379de76248c8c90678f0c5b6f97d4087c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 16 Dec 2019 10:09:37 +1000 Subject: [PATCH] fix up macro use in expr context --- src/macros.rs | 13 ++++++------- tests/macros.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 23378fc5e..f628664b7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -47,7 +47,7 @@ macro_rules! log { #[doc(hidden)] macro_rules! log_impl { // End of macro input - (target: $target:expr, $lvl:expr, ($message:expr)) => { + (target: $target:expr, $lvl:expr, ($message:expr)) => {{ let lvl = $lvl; if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() { $crate::__private_api_log_lit( @@ -56,9 +56,8 @@ macro_rules! log_impl { &($target, __log_module_path!(), __log_file!(), __log_line!()), ); } - }; - - (target: $target:expr, $lvl:expr, ($($arg:expr),*)) => { + }}; + (target: $target:expr, $lvl:expr, ($($arg:expr),*)) => {{ let lvl = $lvl; if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() { $crate::__private_api_log( @@ -68,10 +67,10 @@ macro_rules! log_impl { None, ); } - }; + }}; // // Trailing k-v pairs containing no trailing comma - (target: $target:expr, $lvl:expr, ($($arg:expr),*) { $($key:ident : $value:expr),* }) => { + (target: $target:expr, $lvl:expr, ($($arg:expr),*) { $($key:ident : $value:expr),* }) => {{ let lvl = log::Level::Info; if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() { $crate::__private_api_log( @@ -81,7 +80,7 @@ macro_rules! log_impl { Some(&[$((__log_stringify!($key), &$value)),*]) ); } - }; + }}; // Trailing k-v pairs with trailing comma (target: $target:expr, $lvl:expr, ($($e:expr),*) { $($key:ident : $value:expr,)* }) => { diff --git a/tests/macros.rs b/tests/macros.rs index f41c52ed3..34c89811f 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -7,6 +7,11 @@ fn base() { info!("hello",); } +#[test] +fn base_expr_context() { + let _ = info!("hello"); +} + #[test] fn with_args() { info!("hello {}", "cats"); @@ -14,6 +19,13 @@ fn with_args() { info!("hello {}", "cats",); } +#[test] +fn with_args_expr_context() { + match "cats" { + cats => info!("hello {}", cats), + }; +} + #[test] fn kv() { info!("hello {}", "cats", { @@ -21,3 +33,13 @@ fn kv() { cat_2: "nori", }); } + +#[test] +fn kv_expr_context() { + match "chashu" { + cat_1 => info!("hello {}", "cats", { + cat_1: cat_1, + cat_2: "nori", + }), + }; +}