-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macros: Allow field path segments to be keywords #2925
Conversation
bb89679
to
f87f41f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests! Could we please move them into the tracing
crate, since that's where the macros that they're testing are defined.
f87f41f
to
917065a
Compare
917065a
to
3eb7a9a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
8999a41
to
8f6bb60
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
8f6bb60
to
6a2c043
Compare
This comment was marked as resolved.
This comment was marked as resolved.
6a2c043
to
df0f108
Compare
Finally the stream of unrelated CI failures has ended! 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you!
Hey @hds ! |
This needs a new |
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¹. 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 55091c9#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
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¹. 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 55091c9#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
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¹. 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 55091c9#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
# 0.1.28 (November 26, 2024) ### Changed - Bump MSRV to 1.63 ([#2793]) ### Fixed - Added missing RecordTypes for instrument ([#2781]) - Change order of async and unsafe modifier ([#2864]) - Extract match scrutinee ([#2880]) - Allow field path segments to be keywords ([#2925]) - Support const values for `target` and `name` ([#2941]) ### Documented - Fix backporting error in attributes ([#2780]) [#2780]: #2780 [#2781]: #2781 [#2793]: #2793 [#2864]: #2864 [#2880]: #2880 [#2925]: #2925 [#2941]: #2941
# 0.1.28 (November 26, 2024) ### Changed - Bump MSRV to 1.63 ([#2793]) ### Fixed - Added missing RecordTypes for instrument ([#2781]) - Change order of async and unsafe modifier ([#2864]) - Extract match scrutinee ([#2880]) - Allow field path segments to be keywords ([#2925]) - Support const values for `target` and `name` ([#2941]) ### Documented - Fix backporting error in attributes ([#2780]) [#2780]: #2780 [#2781]: #2781 [#2793]: #2793 [#2864]: #2864 [#2880]: #2880 [#2925]: #2925 [#2941]: #2941
# 0.1.41 (November 25, 2024) [[[crates.io][crate-0.1.41]]] | [[[docs.rs][docs-0.1.41]]] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 25, 2024) [[[crates.io][crate-0.1.41]]] | [[[docs.rs][docs-0.1.41]]] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 25, 2024) [[[crates.io][crate-0.1.41]]] | [[[docs.rs][docs-0.1.41]]] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 25, 2024) [ [crates.io][crate-0.1.41] ] | [ [docs.rs][docs-0.1.41] ] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 25, 2024) [ [crates.io][crate-0.1.41] ] | [ [docs.rs][docs-0.1.41] ] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 27, 2024) [ [crates.io][crate-0.1.41] ] | [ [docs.rs][docs-0.1.41] ] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
# 0.1.41 (November 27, 2024) [ [crates.io][crate-0.1.41] ] | [ [docs.rs][docs-0.1.41] ] This release updates the `tracing-core` dependency to [v0.1.33][core-0.1.33] and the `tracing-attributes` dependency to [v0.1.28][attrs-0.1.28]. ### Added - **core**: Add index API for `Field` ([#2820]) - **core**: Allow `&[u8]` to be recorded as event/span field ([#2954]) ### Changed - Bump MSRV to 1.63 ([#2793]) - **core**: Use const `thread_local`s when possible ([#2838]) ### Fixed - Removed core imports in macros ([#2762]) - **attributes**: Added missing RecordTypes for instrument ([#2781]) - **attributes**: Change order of async and unsafe modifier ([#2864]) - Fix missing field prefixes ([#2878]) - **attributes**: Extract match scrutinee ([#2880]) - Fix non-simple macro usage without message ([#2879]) - Fix event macros with constant field names in the first position ([#2883]) - Allow field path segments to be keywords ([#2925]) - **core**: Fix missed `register_callsite` error ([#2938]) - **attributes**: Support const values for `target` and `name` ([#2941]) - Prefix macro calls with ::core to avoid clashing with local macros ([#3024]) [#2762]: #2762 [#2781]: #2781 [#2793]: #2793 [#2820]: #2820 [#2838]: #2838 [#2864]: #2864 [#2878]: #2878 [#2879]: #2879 [#2880]: #2880 [#2883]: #2883 [#2925]: #2925 [#2938]: #2938 [#2941]: #2941 [#2954]: #2954 [#3024]: #3024 [attrs-0.1.28]: https://github.com/tokio-rs/tracing/releases/tag/tracing-attributes-0.1.28 [core-0.1.33]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.33 [docs-0.1.41]: https://docs.rs/tracing/0.1.41/tracing/ [crate-0.1.41]: https://crates.io/crates/tracing/0.1.41
Motivation
Currently, a keyword like
type
fails compilation as (a path segment of) a field name, for no clear reason. Trying to user#type
instead leads to ther#
being part of the field name, which is unhelpful¹.Solution
Don't require the field path to match a
macro_rules!
expr
, use repeatedtt
instead. I can't tell why this was ever required: The internal stringify macro was introduced in 55091c9#diff-315c02cd05738da173861537577d159833f70f79cfda8cd7cf1a0d7a28ace31b with anexpr
matcher without any explanation, and no tests are failing from making it match upstream'sstringify!
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
intofoo
, but that's a separate change not made in this PR