Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: removed core imports in macros #2762

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,10 @@ pub mod __macro_support {
use crate::{collect::Interest, Metadata};
use core::fmt;
use core::sync::atomic::{AtomicU8, Ordering};
// 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};
kaffarell marked this conversation as resolved.
Show resolved Hide resolved
kaffarell marked this conversation as resolved.
Show resolved Hide resolved

/// Callsite implementation used by macro-generated code.
///
Expand Down
56 changes: 28 additions & 28 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ macro_rules! event {
target: $target,
parent: $parent,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand Down Expand Up @@ -679,7 +679,7 @@ macro_rules! event {
name: $name,
target: $target,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(name: $name:expr, target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand Down Expand Up @@ -737,7 +737,7 @@ macro_rules! event {
target: $target,
parent: $parent,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand Down Expand Up @@ -790,7 +790,7 @@ macro_rules! event {
name: $name,
parent: $parent,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(name: $name:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand Down Expand Up @@ -840,7 +840,7 @@ macro_rules! event {
$crate::event!(
name: $name,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(name: $name:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand Down Expand Up @@ -895,7 +895,7 @@ macro_rules! event {
$crate::event!(
target: $target,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
Expand All @@ -911,7 +911,7 @@ macro_rules! event {
target: module_path!(),
parent: $parent,
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
(parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => (
Expand Down Expand Up @@ -971,7 +971,7 @@ macro_rules! event {
$crate::event!(
target: module_path!(),
$lvl,
{ message = ::core::format_args!($($arg)+), $($fields)* }
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
)
);
($lvl:expr, $($k:ident).+ = $($field:tt)*) => (
Expand Down Expand Up @@ -2805,120 +2805,120 @@ macro_rules! valueset {
// };
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
$next,
)
};

// Handle literal names
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
$next,
$($rest)*
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
$next,
)
};
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => {
$crate::valueset!(
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
$next,
)
};
Expand Down Expand Up @@ -2966,7 +2966,7 @@ macro_rules! valueset {

// Remainder is unparsable, but exists --- must be format args!
(@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => {
$crate::valueset!(@ { (&$next, ::core::option::Option::Some(&::core::format_args!($($rest)+) as &dyn Value)), $($out),* }, $next, )
$crate::valueset!(@ { (&$next, $crate::__macro_support::Option::Some(&$crate::__macro_support::format_args!($($rest)+) as &dyn Value)), $($out),* }, $next, )
};

// === entry ===
Expand All @@ -2977,7 +2977,7 @@ macro_rules! valueset {
let mut iter = $fields.iter();
$fields.value_set($crate::valueset!(
@ { },
::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
$crate::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
$($kvs)+
))
}
Expand Down