Skip to content
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

fix: prefix macro calls with ::core to avoid clashing with local macros #3024

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Jun 30, 2024

Motivation

This commit fixes a bug where a macro call to macros defined in the
standard lib from the tracing and tracing-core crates could be
resolved to a local macro with the same name, causing a compilation
error.

Solution

This commit prefixes these calls with ::core:: to ensure that
they are resolved to the standard library macros.

Fixes: #3023

While this fixes the specific issue at hand, there's likely many macro calls that are impacted by this problem - specifically every call to module_path (there are many). I haven't updated all of those places as I was unsure if that was a good idea as there's about 220 calls of that macro. I also haven't checked for other macros that would also be problematic.

This commit fixes a bug where a macro call to macros defined in the
standard lib from the `tracing` and `tracing-core` crates could be
resolved to a local macro with the same name, causing a compilation
error. This commit prefixes these calls with `::core::` to ensure that
they are resolved to the standard library macros.

Fixes: <tokio-rs#3023>
@joshka joshka requested review from hawkw, carllerche, davidbarsky and a team as code owners June 30, 2024 19:24
Copy link
Contributor

@kaffarell kaffarell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
This is not really optimal as some users have a crate named core. In that case this won't work. We fixed this a well in #2761. Basically it would be best to import these things in __macro_support and then use the full path $crate::__macro_support:: (As we did in #2762).

This ensures that the tracing lib correctly builds when a crate is named
`core`. See tokio-rs#2761 and
tokio-rs#2762 for more info.
@joshka
Copy link
Contributor Author

joshka commented Jul 2, 2024

Wow, that's an interesting problem -

This is not really optimal as some users have a crate named core. In that case this won't work. We fixed this a well in #2761. Basically it would be best to import these things in __macro_support and then use the full path $crate::__macro_support:: (As we did in #2762).

Addressed in 5960e0a by adding these to the __macro_support in tracing / tracing_core. I didn't change all the occurrences of module_path, as these only clash if someone has named a macro module_path. This is less likely than file / line which are small names that have many reasonable use cases.

Copy link
Contributor

@kaffarell kaffarell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@joshka
Copy link
Contributor Author

joshka commented Jul 18, 2024

ping

@joshka
Copy link
Contributor Author

joshka commented Jul 23, 2024

Can this also be backported to the 0.1 branch please? (Happy to add another PR for that if needed)

@davidbarsky davidbarsky merged commit 1898311 into tokio-rs:master Jul 24, 2024
55 checks passed
@joshka joshka deleted the jm/fix-macro-disambiguation branch July 24, 2024 23:57
@hds hds mentioned this pull request Nov 19, 2024
20 tasks
hds pushed a commit that referenced this pull request Nov 22, 2024
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
hds pushed a commit that referenced this pull request Nov 22, 2024
…os (#3024)

fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros

Fixes: <#3023>

This ensures that the tracing lib correctly builds when a crate is named
`core`. See #2761 and
#2762 for more info.
hds added a commit that referenced this pull request Nov 25, 2024
### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

[#2767]: #2767
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

[#2767]: #2767
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#3002]: #3002
[#3024]: #3024

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Sat Nov 23 23:28:42 2024 +0100
#
# On branch hds/tracing-core-0.1.33
# Changes to be committed:
#	modified:   tracing-core/CHANGELOG.md
#	modified:   tracing-core/Cargo.toml
#
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

[#2767]: #2767
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

[#2767]: #2767
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#2954]: #2954
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

Thanks to new contributor @maddiemort for contributing to this release!

[#2767]: #2767
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#2954]: #2954
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Bump MSRV to 1.63 ([#2793])
- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

Thanks to new contributor @maddiemort for contributing to this release!

[#2767]: #2767
[#2793]: #2793
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#2954]: #2954
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 25, 2024
# 0.1.33 (November 25, 2024)

### Added

- Add index API for `Field` ([#2820])
- allow `&[u8]` to be recorded as event/span field ([#2954])

### Changed

- Bump MSRV to 1.63 ([#2793])
- Use const `thread_local`s when possible ([#2838])

### Fixed

- Fix missed `register_callsite` error ([#2938])
- Do not add `valuable/std` feature as dependency unless `valuable` is used ([#3002])
- prefix macro calls with ::core to avoid clashing with local macros ([#3024])

### Documented

- Fix incorrect (incorrectly updated) docs for LevelFilter ([#2767])

Thanks to new contributor @maddiemort for contributing to this release!

[#2767]: #2767
[#2793]: #2793
[#2820]: #2820
[#2838]: #2838
[#2938]: #2938
[#2954]: #2954
[#3002]: #3002
[#3024]: #3024
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
hds added a commit that referenced this pull request Nov 27, 2024
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unqualified line! macro usage inside info! causes issues with ratatui_macros
3 participants