diff --git a/tracing-attributes/tests/fields.rs b/tracing-attributes/tests/fields.rs index 476d17248..29521dd5a 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_fields( + 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 5de45cb75..a4c6b1571 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)*) }; } diff --git a/tracing/tests/event.rs b/tracing/tests/event.rs index 0af0602e9..48a6af774 100644 --- a/tracing/tests/event.rs +++ b/tracing/tests/event.rs @@ -497,3 +497,15 @@ fn constant_field_name() { handle.assert_finished(); } + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[test] +fn keyword_ident_in_field_name() { + let (collector, handle) = collector::mock() + .event(expect::event().with_fields(expect::field("crate").with_value(&"tracing"))) + .only() + .run_with_handle(); + + with_default(collector, || error!(crate = "tracing", "message")); + handle.assert_finished(); +} diff --git a/tracing/tests/span.rs b/tracing/tests/span.rs index e2c4c9239..9a17cd04d 100644 --- a/tracing/tests/span.rs +++ b/tracing/tests/span.rs @@ -7,6 +7,7 @@ use std::thread; use tracing::{ collect::with_default, + error_span, field::{debug, display}, Level, Span, }; @@ -866,3 +867,20 @@ fn constant_field_name() { handle.assert_finished(); } + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[test] +fn keyword_ident_in_field_name_span_macro() { + #[derive(Debug)] + struct Foo; + + let (collector, handle) = collector::mock() + .new_span(expect::span().with_fields(expect::field("self").with_value(&debug(Foo)).only())) + .only() + .run_with_handle(); + + with_default(collector, || { + error_span!("span", self = ?Foo); + }); + handle.assert_finished(); +}