Skip to content

Commit 0759973

Browse files
joshkahds
authored andcommitted
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: <#3023> This ensures that the tracing lib correctly builds when a crate is named `core`. See #2761 and #2762 for more info.
1 parent 40ae82f commit 0759973

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

tracing-core/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@
147147
#[cfg(not(feature = "std"))]
148148
extern crate alloc;
149149

150+
#[doc(hidden)]
151+
pub mod __macro_support {
152+
// Re-export the `core` functions that are used in macros. This allows
153+
// a crate to be named `core` and avoid name clashes.
154+
// See here: https://github.com/tokio-rs/tracing/issues/2761
155+
pub use core::{file, line, module_path, option::Option};
156+
}
157+
150158
/// Statically constructs an [`Identifier`] for the provided [`Callsite`].
151159
///
152160
/// This may be used in contexts such as static initializers.
@@ -244,9 +252,9 @@ macro_rules! metadata {
244252
$name,
245253
$target,
246254
$level,
247-
::core::option::Option::Some(file!()),
248-
::core::option::Option::Some(line!()),
249-
::core::option::Option::Some(module_path!()),
255+
$crate::__macro_support::Option::Some($crate::__macro_support::file!()),
256+
$crate::__macro_support::Option::Some($crate::__macro_support::line!()),
257+
$crate::__macro_support::Option::Some($crate::__macro_support::module_path!()),
250258
$crate::field::FieldSet::new($fields, $crate::identify_callsite!($callsite)),
251259
$kind,
252260
)

tracing/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ pub mod __macro_support {
988988
// Re-export the `core` functions that are used in macros. This allows
989989
// a crate to be named `core` and avoid name clashes.
990990
// See here: https://github.com/tokio-rs/tracing/issues/2761
991-
pub use core::{concat, format_args, iter::Iterator, option::Option};
991+
pub use core::{concat, file, format_args, iter::Iterator, line, option::Option};
992992

993993
/// Callsite implementation used by macro-generated code.
994994
///

tracing/src/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,9 @@ macro_rules! event {
694694
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
695695
name: $crate::__macro_support::concat!(
696696
"event ",
697-
file!(),
697+
$crate::__macro_support::file!(),
698698
":",
699-
line!()
699+
$crate::__macro_support::line!()
700700
),
701701
kind: $crate::metadata::Kind::EVENT,
702702
target: $target,
@@ -855,9 +855,9 @@ macro_rules! event {
855855
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
856856
name: $crate::__macro_support::concat!(
857857
"event ",
858-
file!(),
858+
$crate::__macro_support::file!(),
859859
":",
860-
line!()
860+
$crate::__macro_support::line!()
861861
),
862862
kind: $crate::metadata::Kind::EVENT,
863863
target: $target,
@@ -1188,9 +1188,9 @@ macro_rules! enabled {
11881188
static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! {
11891189
name: $crate::__macro_support::concat!(
11901190
"enabled ",
1191-
file!(),
1191+
$crate::__macro_support::file!(),
11921192
":",
1193-
line!()
1193+
$crate::__macro_support::line!()
11941194
),
11951195
kind: $kind.hint(),
11961196
target: $target,

0 commit comments

Comments
 (0)