tokio-rs / tracing

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

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

Closed joshka closed 2 months ago

joshka commented 3 months ago

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: https://github.com/tokio-rs/tracing/issues/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.

joshka commented 3 months ago

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 5960e0aa 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.

joshka commented 2 months ago

ping

joshka commented 2 months ago

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