Skip to content

Commit d3ea43a

Browse files
committed
tracing: removed core imports in macros (tokio-rs#2762)
When a user has a crate named `core`, it can cause issues because our crates import from `::core::*`. Now we are importing from `$crate::__macro_support::*` and there will be no more name clashes.
1 parent 5a2fc1c commit d3ea43a

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

tracing/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,10 @@ pub mod subscriber;
984984
pub mod __macro_support {
985985
pub use crate::callsite::Callsite;
986986
use crate::{subscriber::Interest, Metadata};
987-
pub use core::concat;
987+
// Re-export the `core` functions that are used in macros. This allows
988+
// a crate to be named `core` and avoid name clashes.
989+
// See here: https://github.com/tokio-rs/tracing/issues/2761
990+
pub use core::{concat, format_args, iter::Iterator, option::Option};
988991

989992
/// Callsite implementation used by macro-generated code.
990993
///

tracing/src/macros.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ macro_rules! event {
627627
target: $target,
628628
parent: $parent,
629629
$lvl,
630-
{ message = ::core::format_args!($($arg)+), $($fields)* }
630+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
631631
)
632632
);
633633
(name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -678,7 +678,7 @@ macro_rules! event {
678678
name: $name,
679679
target: $target,
680680
$lvl,
681-
{ message = ::core::format_args!($($arg)+), $($fields)* }
681+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
682682
)
683683
);
684684
(name: $name:expr, target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -736,7 +736,7 @@ macro_rules! event {
736736
target: $target,
737737
parent: $parent,
738738
$lvl,
739-
{ message = ::core::format_args!($($arg)+), $($fields)* }
739+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
740740
)
741741
);
742742
(target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -789,7 +789,7 @@ macro_rules! event {
789789
name: $name,
790790
parent: $parent,
791791
$lvl,
792-
{ message = ::core::format_args!($($arg)+), $($fields)* }
792+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
793793
)
794794
);
795795
(name: $name:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -839,7 +839,7 @@ macro_rules! event {
839839
$crate::event!(
840840
name: $name,
841841
$lvl,
842-
{ message = ::core::format_args!($($arg)+), $($fields)* }
842+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
843843
)
844844
);
845845
(name: $name:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -894,7 +894,7 @@ macro_rules! event {
894894
$crate::event!(
895895
target: $target,
896896
$lvl,
897-
{ message = ::core::format_args!($($arg)+), $($fields)* }
897+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
898898
)
899899
);
900900
(target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -910,7 +910,7 @@ macro_rules! event {
910910
target: module_path!(),
911911
parent: $parent,
912912
$lvl,
913-
{ message = ::core::format_args!($($arg)+), $($fields)* }
913+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
914914
)
915915
);
916916
(parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => (
@@ -970,7 +970,7 @@ macro_rules! event {
970970
$crate::event!(
971971
target: module_path!(),
972972
$lvl,
973-
{ message = ::core::format_args!($($arg)+), $($fields)* }
973+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
974974
)
975975
);
976976
( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => (
@@ -2802,120 +2802,120 @@ macro_rules! valueset {
28022802
// };
28032803
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
28042804
$crate::valueset!(
2805-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2805+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28062806
$next,
28072807
$($rest)*
28082808
)
28092809
};
28102810
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
28112811
$crate::valueset!(
2812-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2812+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28132813
$next,
28142814
$($rest)*
28152815
)
28162816
};
28172817
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => {
28182818
$crate::valueset!(
2819-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2819+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
28202820
$next,
28212821
$($rest)*
28222822
)
28232823
};
28242824
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => {
28252825
$crate::valueset!(
2826-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
2826+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
28272827
$next,
28282828
$($rest)*
28292829
)
28302830
};
28312831
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => {
28322832
$crate::valueset!(
2833-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
2833+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
28342834
$next,
28352835
$($rest)*
28362836
)
28372837
};
28382838
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => {
28392839
$crate::valueset!(
2840-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
2840+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
28412841
$next,
28422842
$($rest)*
28432843
)
28442844
};
28452845
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => {
28462846
$crate::valueset!(
2847-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2847+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28482848
$next,
28492849
)
28502850
};
28512851
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => {
28522852
$crate::valueset!(
2853-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2853+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28542854
$next,
28552855
)
28562856
};
28572857
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => {
28582858
$crate::valueset!(
2859-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2859+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
28602860
$next,
28612861
)
28622862
};
28632863
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => {
28642864
$crate::valueset!(
2865-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
2865+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
28662866
$next,
28672867
)
28682868
};
28692869
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => {
28702870
$crate::valueset!(
2871-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
2871+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
28722872
$next,
28732873
)
28742874
};
28752875
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => {
28762876
$crate::valueset!(
2877-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
2877+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
28782878
$next,
28792879
)
28802880
};
28812881

28822882
// Handle literal names
28832883
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => {
28842884
$crate::valueset!(
2885-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2885+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28862886
$next,
28872887
$($rest)*
28882888
)
28892889
};
28902890
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => {
28912891
$crate::valueset!(
2892-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2892+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28932893
$next,
28942894
$($rest)*
28952895
)
28962896
};
28972897
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => {
28982898
$crate::valueset!(
2899-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2899+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
29002900
$next,
29012901
$($rest)*
29022902
)
29032903
};
29042904
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => {
29052905
$crate::valueset!(
2906-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2906+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
29072907
$next,
29082908
)
29092909
};
29102910
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => {
29112911
$crate::valueset!(
2912-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2912+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
29132913
$next,
29142914
)
29152915
};
29162916
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => {
29172917
$crate::valueset!(
2918-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2918+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
29192919
$next,
29202920
)
29212921
};
@@ -2963,7 +2963,7 @@ macro_rules! valueset {
29632963

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

29692969
// === entry ===
@@ -2974,7 +2974,7 @@ macro_rules! valueset {
29742974
let mut iter = $fields.iter();
29752975
$fields.value_set($crate::valueset!(
29762976
@ { },
2977-
::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
2977+
$crate::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
29782978
$($kvs)+
29792979
))
29802980
}

0 commit comments

Comments
 (0)