Skip to content

Commit 307646e

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 caef040 commit 307646e

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

tracing/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,10 @@ pub mod __macro_support {
10011001
use crate::{collect::Interest, Metadata};
10021002
use core::fmt;
10031003
use core::sync::atomic::{AtomicU8, Ordering};
1004+
// Re-export the `core` functions that are used in macros. This allows
1005+
// a crate to be named `core` and avoid name clashes.
1006+
// See here: https://github.com/tokio-rs/tracing/issues/2761
1007+
pub use core::{concat, format_args, iter::Iterator, option::Option};
10041008

10051009
/// Callsite implementation used by macro-generated code.
10061010
///

tracing/src/macros.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ macro_rules! event {
628628
target: $target,
629629
parent: $parent,
630630
$lvl,
631-
{ message = ::core::format_args!($($arg)+), $($fields)* }
631+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
632632
)
633633
);
634634
(name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -679,7 +679,7 @@ macro_rules! event {
679679
name: $name,
680680
target: $target,
681681
$lvl,
682-
{ message = ::core::format_args!($($arg)+), $($fields)* }
682+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
683683
)
684684
);
685685
(name: $name:expr, target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -737,7 +737,7 @@ macro_rules! event {
737737
target: $target,
738738
parent: $parent,
739739
$lvl,
740-
{ message = ::core::format_args!($($arg)+), $($fields)* }
740+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
741741
)
742742
);
743743
(target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -790,7 +790,7 @@ macro_rules! event {
790790
name: $name,
791791
parent: $parent,
792792
$lvl,
793-
{ message = ::core::format_args!($($arg)+), $($fields)* }
793+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
794794
)
795795
);
796796
(name: $name:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -840,7 +840,7 @@ macro_rules! event {
840840
$crate::event!(
841841
name: $name,
842842
$lvl,
843-
{ message = ::core::format_args!($($arg)+), $($fields)* }
843+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
844844
)
845845
);
846846
(name: $name:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -895,7 +895,7 @@ macro_rules! event {
895895
$crate::event!(
896896
target: $target,
897897
$lvl,
898-
{ message = ::core::format_args!($($arg)+), $($fields)* }
898+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
899899
)
900900
);
901901
(target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => (
@@ -911,7 +911,7 @@ macro_rules! event {
911911
target: module_path!(),
912912
parent: $parent,
913913
$lvl,
914-
{ message = ::core::format_args!($($arg)+), $($fields)* }
914+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
915915
)
916916
);
917917
(parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => (
@@ -971,7 +971,7 @@ macro_rules! event {
971971
$crate::event!(
972972
target: module_path!(),
973973
$lvl,
974-
{ message = ::core::format_args!($($arg)+), $($fields)* }
974+
{ message = $crate::__macro_support::format_args!($($arg)+), $($fields)* }
975975
)
976976
);
977977
($lvl:expr, $($k:ident).+ = $($field:tt)*) => (
@@ -2805,120 +2805,120 @@ macro_rules! valueset {
28052805
// };
28062806
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => {
28072807
$crate::valueset!(
2808-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2808+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28092809
$next,
28102810
$($rest)*
28112811
)
28122812
};
28132813
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => {
28142814
$crate::valueset!(
2815-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2815+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28162816
$next,
28172817
$($rest)*
28182818
)
28192819
};
28202820
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => {
28212821
$crate::valueset!(
2822-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2822+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
28232823
$next,
28242824
$($rest)*
28252825
)
28262826
};
28272827
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => {
28282828
$crate::valueset!(
2829-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
2829+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
28302830
$next,
28312831
$($rest)*
28322832
)
28332833
};
28342834
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => {
28352835
$crate::valueset!(
2836-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
2836+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
28372837
$next,
28382838
$($rest)*
28392839
)
28402840
};
28412841
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => {
28422842
$crate::valueset!(
2843-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
2843+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
28442844
$next,
28452845
$($rest)*
28462846
)
28472847
};
28482848
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => {
28492849
$crate::valueset!(
2850-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2850+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28512851
$next,
28522852
)
28532853
};
28542854
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => {
28552855
$crate::valueset!(
2856-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2856+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28572857
$next,
28582858
)
28592859
};
28602860
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => {
28612861
$crate::valueset!(
2862-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2862+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
28632863
$next,
28642864
)
28652865
};
28662866
(@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => {
28672867
$crate::valueset!(
2868-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) },
2868+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$($k).+ as &dyn Value)) },
28692869
$next,
28702870
)
28712871
};
28722872
(@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => {
28732873
$crate::valueset!(
2874-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) },
2874+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$($k).+) as &dyn Value)) },
28752875
$next,
28762876
)
28772877
};
28782878
(@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => {
28792879
$crate::valueset!(
2880-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) },
2880+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$($k).+) as &dyn Value)) },
28812881
$next,
28822882
)
28832883
};
28842884

28852885
// Handle literal names
28862886
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => {
28872887
$crate::valueset!(
2888-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2888+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
28892889
$next,
28902890
$($rest)*
28912891
)
28922892
};
28932893
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => {
28942894
$crate::valueset!(
2895-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2895+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
28962896
$next,
28972897
$($rest)*
28982898
)
28992899
};
29002900
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => {
29012901
$crate::valueset!(
2902-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2902+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
29032903
$next,
29042904
$($rest)*
29052905
)
29062906
};
29072907
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => {
29082908
$crate::valueset!(
2909-
@ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) },
2909+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&debug(&$val) as &dyn Value)) },
29102910
$next,
29112911
)
29122912
};
29132913
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => {
29142914
$crate::valueset!(
2915-
@ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) },
2915+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&display(&$val) as &dyn Value)) },
29162916
$next,
29172917
)
29182918
};
29192919
(@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => {
29202920
$crate::valueset!(
2921-
@ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) },
2921+
@ { $($out),*, (&$next, $crate::__macro_support::Option::Some(&$val as &dyn Value)) },
29222922
$next,
29232923
)
29242924
};
@@ -2966,7 +2966,7 @@ macro_rules! valueset {
29662966

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

29722972
// === entry ===
@@ -2977,7 +2977,7 @@ macro_rules! valueset {
29772977
let mut iter = $fields.iter();
29782978
$fields.value_set($crate::valueset!(
29792979
@ { },
2980-
::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
2980+
$crate::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
29812981
$($kvs)+
29822982
))
29832983
}

0 commit comments

Comments
 (0)