Skip to content

Commit 1898311

Browse files
authored
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 28b3ce7 commit 1898311

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

tracing-core/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@
165165
#[cfg(feature = "alloc")]
166166
extern crate alloc;
167167

168+
#[doc(hidden)]
169+
pub mod __macro_support {
170+
// Re-export the `core` functions that are used in macros. This allows
171+
// a crate to be named `core` and avoid name clashes.
172+
// See here: https://github.com/tokio-rs/tracing/issues/2761
173+
pub use core::{file, line, module_path, option::Option};
174+
}
175+
168176
/// Statically constructs an [`Identifier`] for the provided [`Callsite`].
169177
///
170178
/// This may be used in contexts, such as static initializers, where the
@@ -264,9 +272,9 @@ macro_rules! metadata {
264272
$name,
265273
$target,
266274
$level,
267-
::core::option::Option::Some(file!()),
268-
::core::option::Option::Some(line!()),
269-
::core::option::Option::Some(module_path!()),
275+
$crate::__macro_support::Option::Some($crate::__macro_support::file!()),
276+
$crate::__macro_support::Option::Some($crate::__macro_support::line!()),
277+
$crate::__macro_support::Option::Some($crate::__macro_support::module_path!()),
270278
$crate::field::FieldSet::new($fields, $crate::identify_callsite!($callsite)),
271279
$kind,
272280
)

tracing/src/lib.rs

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

10101010
/// Callsite implementation used by macro-generated code.
10111011
///

tracing/src/macros.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,11 @@ macro_rules! event {
693693
(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({
694694
use $crate::__macro_support::Callsite as _;
695695
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
696-
name: concat!(
696+
name: $crate::__macro_support::concat!(
697697
"event ",
698-
file!(),
698+
$crate::__macro_support::file!(),
699699
":",
700-
line!()
700+
$crate::__macro_support::line!()
701701
),
702702
kind: $crate::metadata::Kind::EVENT,
703703
target: $target,
@@ -854,11 +854,11 @@ macro_rules! event {
854854
(target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({
855855
use $crate::__macro_support::Callsite as _;
856856
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
857-
name: concat!(
857+
name: $crate::__macro_support::concat!(
858858
"event ",
859-
file!(),
859+
$crate::__macro_support::file!(),
860860
":",
861-
line!()
861+
$crate::__macro_support::line!()
862862
),
863863
kind: $crate::metadata::Kind::EVENT,
864864
target: $target,
@@ -1184,11 +1184,11 @@ macro_rules! enabled {
11841184
if $crate::level_enabled!($lvl) {
11851185
use $crate::__macro_support::Callsite as _;
11861186
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
1187-
name: concat!(
1187+
name: $crate::__macro_support::concat!(
11881188
"enabled ",
1189-
file!(),
1189+
$crate::__macro_support::file!(),
11901190
":",
1191-
line!()
1191+
$crate::__macro_support::line!()
11921192
),
11931193
kind: $kind.hint(),
11941194
target: $target,

0 commit comments

Comments
 (0)