Skip to content

Commit

Permalink
fix: use __macro_support:: instead of ::core:: in macros
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshka committed Jul 2, 2024
1 parent f1ab24e commit 5960e0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 11 additions & 3 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
#[cfg(feature = "alloc")]
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, where the
Expand Down Expand Up @@ -264,9 +272,9 @@ macro_rules! metadata {
$name,
$target,
$level,
::core::option::Option::Some(::core::file!()),
::core::option::Option::Some(::core::line!()),
::core::option::Option::Some(::core::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,
)
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,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.
///
Expand Down
18 changes: 9 additions & 9 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,11 @@ macro_rules! event {
(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({
use $crate::__macro_support::Callsite as _;
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
name: ::core::concat!(
name: $crate::__macro_support::concat!(
"event ",
::core::file!(),
$crate::__macro_support::file!(),
":",
::core::line!()
$crate::__macro_support::line!()
),
kind: $crate::metadata::Kind::EVENT,
target: $target,
Expand Down Expand Up @@ -854,11 +854,11 @@ macro_rules! event {
(target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({
use $crate::__macro_support::Callsite as _;
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
name: ::core::concat!(
name: $crate::__macro_support::concat!(
"event ",
::core::file!(),
$crate::__macro_support::file!(),
":",
::core::line!()
$crate::__macro_support::line!()
),
kind: $crate::metadata::Kind::EVENT,
target: $target,
Expand Down Expand Up @@ -1184,11 +1184,11 @@ macro_rules! enabled {
if $crate::level_enabled!($lvl) {
use $crate::__macro_support::Callsite as _;
static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! {
name: ::core::concat!(
name: $crate::__macro_support::concat!(
"enabled ",
::core::file!(),
$crate::__macro_support::file!(),
":",
::core::line!()
$crate::__macro_support::line!()
),
kind: $kind.hint(),
target: $target,
Expand Down

0 comments on commit 5960e0a

Please sign in to comment.