Skip to content

Commit bb89679

Browse files
committed
macros: Allow field path segments to be keywords
1 parent 908cc43 commit bb89679

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

tracing-attributes/tests/fields.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fn fn_string(s: String) {
3434
let _ = s;
3535
}
3636

37+
#[instrument(fields(keywords.impl.type.fn = _arg), skip(_arg))]
38+
fn fn_keyword_ident_in_field(_arg: &str) {}
39+
3740
#[derive(Debug)]
3841
struct HasField {
3942
my_field: &'static str,
@@ -146,6 +149,16 @@ fn string_field() {
146149
});
147150
}
148151

152+
#[test]
153+
fn keyword_ident_in_field_name() {
154+
let span = expect::span().with_field(
155+
expect::field("keywords.impl.type.fn")
156+
.with_value(&"test")
157+
.only(),
158+
);
159+
run_test(span, || fn_keyword_ident_in_field("test"));
160+
}
161+
149162
fn run_test<F: FnOnce() -> T, T>(span: NewSpan, fun: F) {
150163
let (collector, handle) = collector::mock()
151164
.new_span(span)

tracing/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,8 +3069,8 @@ macro_rules! level_to_log {
30693069
#[doc(hidden)]
30703070
#[macro_export]
30713071
macro_rules! __tracing_stringify {
3072-
($s:expr) => {
3073-
stringify!($s)
3072+
($($t:tt)*) => {
3073+
stringify!($($t)*)
30743074
};
30753075
}
30763076

0 commit comments

Comments
 (0)