Replace local_inner_macros with $crate (#729)

This commit is contained in:
Taiki Endo 2020-05-22 22:10:03 +09:00 committed by GitHub
parent 81722c2c9d
commit 18764d149f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 27 deletions

View File

@ -19,15 +19,15 @@ pub(crate) mod lazy;
#[doc(hidden)] #[doc(hidden)]
pub(crate) use core::ops::Deref as __Deref; pub(crate) use core::ops::Deref as __Deref;
#[macro_export(local_inner_macros)] #[macro_export]
#[doc(hidden)] #[doc(hidden)]
macro_rules! __lazy_static_internal { macro_rules! __lazy_static_internal {
// optional visibility restrictions are wrapped in `()` to allow for // optional visibility restrictions are wrapped in `()` to allow for
// explicitly passing otherwise implicit information about private items // explicitly passing otherwise implicit information about private items
($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { ($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
__lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N); $crate::__lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N);
__lazy_static_internal!(@TAIL, $N : $T = $e); $crate::__lazy_static_internal!(@TAIL, $N : $T = $e);
lazy_static!($($t)*); $crate::lazy_static!($($t)*);
}; };
(@TAIL, $N:ident : $T:ty = $e:expr) => { (@TAIL, $N:ident : $T:ty = $e:expr) => {
impl $crate::lazy_static::__Deref for $N { impl $crate::lazy_static::__Deref for $N {
@ -38,7 +38,7 @@ macro_rules! __lazy_static_internal {
#[inline(always)] #[inline(always)]
fn __stability() -> &'static $T { fn __stability() -> &'static $T {
__lazy_static_create!(LAZY, $T); $crate::__lazy_static_create!(LAZY, $T);
LAZY.get(__static_ref_initialize) LAZY.get(__static_ref_initialize)
} }
__stability() __stability()
@ -63,18 +63,18 @@ macro_rules! __lazy_static_internal {
() => () () => ()
} }
#[macro_export(local_inner_macros)] #[macro_export]
/// lazy_static (suppress docs_missing warning) #[doc(hidden)]
macro_rules! lazy_static { macro_rules! lazy_static {
($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { ($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
// use `()` to explicitly forward the information about private items // use `()` to explicitly forward the information about private items
__lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*); $crate::__lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*);
}; };
($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { ($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
__lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*); $crate::__lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*);
}; };
($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { ($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
__lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*); $crate::__lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*);
}; };
() => () () => ()
} }

View File

@ -177,7 +177,7 @@ macro_rules! metadata {
callsite: $callsite:expr, callsite: $callsite:expr,
kind: $kind:expr kind: $kind:expr
) => { ) => {
metadata! { $crate::metadata! {
name: $name, name: $name,
target: $target, target: $target,
level: $level, level: $level,

View File

@ -1,10 +1,7 @@
//! Compare to the example given in the documentation for the `std::dbg` macro. //! Compare to the example given in the documentation for the `std::dbg` macro.
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]
#[macro_use] use tracing_macros::dbg;
extern crate tracing;
#[macro_use]
extern crate tracing_macros;
fn factorial(n: u32) -> u32 { fn factorial(n: u32) -> u32 {
if dbg!(n <= 1) { if dbg!(n <= 1) {

View File

@ -1,19 +1,17 @@
extern crate tracing;
/// Alias of `dbg!` for avoiding conflicts with the `std::dbg!` macro. /// Alias of `dbg!` for avoiding conflicts with the `std::dbg!` macro.
#[macro_export(local_inner_macros)] #[macro_export]
macro_rules! trace_dbg { macro_rules! trace_dbg {
(target: $target:expr, level: $level:expr, $ex:expr) => { (target: $target:expr, level: $level:expr, $ex:expr) => {
dbg!(target: $target, level: $level, $ex) $crate::dbg!(target: $target, level: $level, $ex)
}; };
(level: $level:expr, $ex:expr) => { (level: $level:expr, $ex:expr) => {
dbg!(target: module_path!(), level: $level, $ex) $crate::dbg!(target: module_path!(), level: $level, $ex)
}; };
(target: $target:expr, $ex:expr) => { (target: $target:expr, $ex:expr) => {
dbg!(target: $target, level: tracing::Level::DEBUG, $ex) $crate::dbg!(target: $target, level: tracing::Level::DEBUG, $ex)
}; };
($ex:expr) => { ($ex:expr) => {
dbg!(level: tracing::Level::DEBUG, $ex) $crate::dbg!(level: tracing::Level::DEBUG, $ex)
}; };
} }
@ -31,7 +29,7 @@ macro_rules! dbg {
field::{debug, Value}, field::{debug, Value},
Event, Id, Subscriber, Event, Id, Subscriber,
}; };
let callsite = callsite! { let callsite = tracing::callsite! {
name: concat!("event:trace_dbg(", stringify!($ex), ")"), name: concat!("event:trace_dbg(", stringify!($ex), ")"),
kind: tracing::metadata::Kind::EVENT, kind: tracing::metadata::Kind::EVENT,
target: $target, target: $target,
@ -39,7 +37,7 @@ macro_rules! dbg {
fields: value, fields: value,
}; };
let val = $ex; let val = $ex;
if is_enabled!(callsite) { if tracing::is_enabled!(callsite) {
let meta = callsite.metadata(); let meta = callsite.metadata();
let fields = meta.fields(); let fields = meta.fields();
let key = meta let key = meta
@ -55,12 +53,12 @@ macro_rules! dbg {
val val
}}; }};
(level: $level:expr, $ex:expr) => { (level: $level:expr, $ex:expr) => {
dbg!(target: module_path!(), level: $level, $ex) $crate::dbg!(target: module_path!(), level: $level, $ex)
}; };
(target: $target:expr, $ex:expr) => { (target: $target:expr, $ex:expr) => {
dbg!(target: $target, level: tracing::Level::DEBUG, $ex) $crate::dbg!(target: $target, level: tracing::Level::DEBUG, $ex)
}; };
($ex:expr) => { ($ex:expr) => {
dbg!(level: tracing::Level::DEBUG, $ex) $crate::dbg!(level: tracing::Level::DEBUG, $ex)
}; };
} }