Skip to content

Commit

Permalink
macros: Allow field path segments to be keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Apr 22, 2024
1 parent 908cc43 commit bb89679
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions tracing-attributes/tests/fields.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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<F: FnOnce() -> T, T>(span: NewSpan, fun: F) {
let (collector, handle) = collector::mock()
.new_span(span)
Expand Down
4 changes: 2 additions & 2 deletions tracing/src/macros.rs
Expand Up @@ -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)*)
};
}

Expand Down

0 comments on commit bb89679

Please sign in to comment.