From bb896792e8af6d5596a5fce1b7710c7985867853 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 3 Apr 2024 15:18:34 +0200 Subject: [PATCH] macros: Allow field path segments to be keywords --- tracing-attributes/tests/fields.rs | 13 +++++++++++++ tracing/src/macros.rs | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tracing-attributes/tests/fields.rs b/tracing-attributes/tests/fields.rs index 476d172482..28b3a85299 100644 --- a/tracing-attributes/tests/fields.rs +++ b/tracing-attributes/tests/fields.rs @@ -34,6 +34,9 @@ fn fn_string(s: String) { let _ = s; } +#[instrument(fields(keywords.impl.type.fn = _arg), skip(_arg))] +fn fn_keyword_ident_in_field(_arg: &str) {} + #[derive(Debug)] struct HasField { my_field: &'static str, @@ -146,6 +149,16 @@ fn string_field() { }); } +#[test] +fn keyword_ident_in_field_name() { + let span = expect::span().with_field( + expect::field("keywords.impl.type.fn") + .with_value(&"test") + .only(), + ); + run_test(span, || fn_keyword_ident_in_field("test")); +} + fn run_test T, T>(span: NewSpan, fun: F) { let (collector, handle) = collector::mock() .new_span(span) diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index 5de45cb75b..a4c6b15718 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -3069,8 +3069,8 @@ macro_rules! level_to_log { #[doc(hidden)] #[macro_export] macro_rules! __tracing_stringify { - ($s:expr) => { - stringify!($s) + ($($t:tt)*) => { + stringify!($($t)*) }; }