tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.39k stars 707 forks source link

macros: Allow field path segments to be keywords #2925

Closed svix-jplatte closed 3 months ago

svix-jplatte commented 6 months ago

Motivation

Currently, a keyword like type fails compilation as (a path segment of) a field name, for no clear reason. Trying to use r#type instead leads to the r# being part of the field name, which is unhelpful¹.

Solution

Don't require the field path to match a macro_rules! expr, use repeated tt instead. I can't tell why this was ever required: The internal stringify macro was introduced in https://github.com/tokio-rs/tracing/commit/55091c92edb537bfc126e32f1f24acd614ad9fe0#diff-315c02cd05738da173861537577d159833f70f79cfda8cd7cf1a0d7a28ace31b with an expr matcher without any explanation, and no tests are failing from making it match upstream's stringify! input format.

Special thanks to whoever implemented the unstable macro-backtrace feature in rustc, otherwise this would have been nigh impossible to track down!

¹ this can likely be fixed too by some sort of "unraw" macro that turns r#foo into foo, but that's a separate change not made in this PR

svix-jplatte commented 5 months ago

Rebased to fix CI (hopefully).

svix-jplatte commented 4 months ago

I'm working on fixing the new CI failures ^^

svix-jplatte commented 4 months ago

Rebased to fix another round of CI failures, hoping it's the last time :crossed_fingers:

svix-jplatte commented 4 months ago

CI failed again /o\ (error)

Looks like a Windows-specific nextest bug? :melting_face:

svix-jplatte commented 4 months ago

And after another rebase, we have an ICE! Fix seems to be https://github.com/rust-lang/rust/pull/125493.

svix-jplatte commented 3 months ago

Finally the stream of unrelated CI failures has ended! :sweat_smile: Can this be merged now? :)

nimrodkor commented 4 days ago

Hey @hds ! I see you merged this PR - can we get a fresh version of tracing-attributes that supports this?

svix-jplatte commented 3 days ago

This needs a new tracing release, not tracing-attributes.