From 322c7e4e66604f5c2c14d339763fac73054d7b76 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Wed, 24 Jul 2024 10:53:17 -0700 Subject: [PATCH] fix: prefix macro calls with ::core to avoid clashing with local macros (#3024) fix: prefix macro calls with `__macro_support ` to avoid clashes with local macros Fixes: This ensures that the tracing lib correctly builds when a crate is named `core`. See https://github.com/tokio-rs/tracing/issues/2761 and https://github.com/tokio-rs/tracing/issues/2762 for more info. --- tracing-core/src/lib.rs | 14 +++++++++++--- tracing/src/lib.rs | 2 +- tracing/src/macros.rs | 12 ++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tracing-core/src/lib.rs b/tracing-core/src/lib.rs index bcb13533d..4286d88c3 100644 --- a/tracing-core/src/lib.rs +++ b/tracing-core/src/lib.rs @@ -147,6 +147,14 @@ #[cfg(not(feature = "std"))] extern crate alloc; +#[doc(hidden)] +pub mod __macro_support { + // Re-export the `core` functions that are used in macros. This allows + // a crate to be named `core` and avoid name clashes. + // See here: https://github.com/tokio-rs/tracing/issues/2761 + pub use core::{file, line, module_path, option::Option}; +} + /// Statically constructs an [`Identifier`] for the provided [`Callsite`]. /// /// This may be used in contexts such as static initializers. @@ -244,9 +252,9 @@ macro_rules! metadata { $name, $target, $level, - ::core::option::Option::Some(file!()), - ::core::option::Option::Some(line!()), - ::core::option::Option::Some(module_path!()), + $crate::__macro_support::Option::Some($crate::__macro_support::file!()), + $crate::__macro_support::Option::Some($crate::__macro_support::line!()), + $crate::__macro_support::Option::Some($crate::__macro_support::module_path!()), $crate::field::FieldSet::new($fields, $crate::identify_callsite!($callsite)), $kind, ) diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index 3425da591..2c01d6d45 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -988,7 +988,7 @@ pub mod __macro_support { // Re-export the `core` functions that are used in macros. This allows // a crate to be named `core` and avoid name clashes. // See here: https://github.com/tokio-rs/tracing/issues/2761 - pub use core::{concat, format_args, iter::Iterator, option::Option}; + pub use core::{concat, file, format_args, iter::Iterator, line, option::Option}; /// Callsite implementation used by macro-generated code. /// diff --git a/tracing/src/macros.rs b/tracing/src/macros.rs index e7cbf9546..156334a35 100644 --- a/tracing/src/macros.rs +++ b/tracing/src/macros.rs @@ -694,9 +694,9 @@ macro_rules! event { static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { name: $crate::__macro_support::concat!( "event ", - file!(), + $crate::__macro_support::file!(), ":", - line!() + $crate::__macro_support::line!() ), kind: $crate::metadata::Kind::EVENT, target: $target, @@ -855,9 +855,9 @@ macro_rules! event { static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { name: $crate::__macro_support::concat!( "event ", - file!(), + $crate::__macro_support::file!(), ":", - line!() + $crate::__macro_support::line!() ), kind: $crate::metadata::Kind::EVENT, target: $target, @@ -1188,9 +1188,9 @@ macro_rules! enabled { static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { name: $crate::__macro_support::concat!( "enabled ", - file!(), + $crate::__macro_support::file!(), ":", - line!() + $crate::__macro_support::line!() ), kind: $kind.hint(), target: $target,