Skip to content

Commit 9d052b1

Browse files
committed
Remove local_inner_macros usage
1 parent e9123d6 commit 9d052b1

File tree

2 files changed

+26
-67
lines changed

2 files changed

+26
-67
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ pub fn __private_api_enabled(level: Level, target: &str) -> bool {
15231523
#[doc(hidden)]
15241524
pub mod __private_api {
15251525
pub use std::option::Option;
1526+
pub use std::{file, format_args, line, module_path, stringify};
15261527
}
15271528

15281529
/// The statically resolved maximum log level.

src/macros.rs

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
/// data.0, data.1, private_data);
2828
/// # }
2929
/// ```
30-
#[macro_export(local_inner_macros)]
30+
#[macro_export]
3131
macro_rules! log {
3232
// log!(target: "my_target", Level::Info, key1 = 42, key2 = true; "a {} event", "log");
3333
(target: $target:expr, $lvl:expr, $($key:tt = $value:expr),+; $($arg:tt)+) => ({
3434
let lvl = $lvl;
3535
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
3636
$crate::__private_api_log(
37-
__log_format_args!($($arg)+),
37+
$crate::__private_api::format_args!($($arg)+),
3838
lvl,
39-
&($target, __log_module_path!(), __log_file!(), __log_line!()),
40-
$crate::__private_api::Option::Some(&[$((__log_key!($key), &$value)),+])
39+
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!(), $crate::__private_api::line!()),
40+
$crate::__private_api::Option::Some(&[$(($crate::__log_key!($key), &$value)),+])
4141
);
4242
}
4343
});
@@ -47,16 +47,16 @@ macro_rules! log {
4747
let lvl = $lvl;
4848
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
4949
$crate::__private_api_log(
50-
__log_format_args!($($arg)+),
50+
$crate::__private_api::format_args!($($arg)+),
5151
lvl,
52-
&($target, __log_module_path!(), __log_file!(), __log_line!()),
52+
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!(), $crate::__private_api::line!()),
5353
$crate::__private_api::Option::None,
5454
);
5555
}
5656
});
5757

5858
// log!(Level::Info, "a log event")
59-
($lvl:expr, $($arg:tt)+) => (log!(target: __log_module_path!(), $lvl, $($arg)+));
59+
($lvl:expr, $($arg:tt)+) => ($crate::log!(target: $crate::__private_api::module_path!(), $lvl, $($arg)+));
6060
}
6161

6262
/// Logs a message at the error level.
@@ -73,14 +73,14 @@ macro_rules! log {
7373
/// error!(target: "app_events", "App Error: {}, Port: {}", err_info, 22);
7474
/// # }
7575
/// ```
76-
#[macro_export(local_inner_macros)]
76+
#[macro_export]
7777
macro_rules! error {
7878
// error!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
7979
// error!(target: "my_target", "a {} event", "log")
80-
(target: $target:expr, $($arg:tt)+) => (log!(target: $target, $crate::Level::Error, $($arg)+));
80+
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Error, $($arg)+));
8181

8282
// error!("a {} event", "log")
83-
($($arg:tt)+) => (log!($crate::Level::Error, $($arg)+))
83+
($($arg:tt)+) => ($crate::log!($crate::Level::Error, $($arg)+))
8484
}
8585

8686
/// Logs a message at the warn level.
@@ -97,14 +97,14 @@ macro_rules! error {
9797
/// warn!(target: "input_events", "App received warning: {}", warn_description);
9898
/// # }
9999
/// ```
100-
#[macro_export(local_inner_macros)]
100+
#[macro_export]
101101
macro_rules! warn {
102102
// warn!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
103103
// warn!(target: "my_target", "a {} event", "log")
104-
(target: $target:expr, $($arg:tt)+) => (log!(target: $target, $crate::Level::Warn, $($arg)+));
104+
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Warn, $($arg)+));
105105

106106
// warn!("a {} event", "log")
107-
($($arg:tt)+) => (log!($crate::Level::Warn, $($arg)+))
107+
($($arg:tt)+) => ($crate::log!($crate::Level::Warn, $($arg)+))
108108
}
109109

110110
/// Logs a message at the info level.
@@ -123,14 +123,14 @@ macro_rules! warn {
123123
/// conn_info.port, conn_info.speed);
124124
/// # }
125125
/// ```
126-
#[macro_export(local_inner_macros)]
126+
#[macro_export]
127127
macro_rules! info {
128128
// info!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
129129
// info!(target: "my_target", "a {} event", "log")
130-
(target: $target:expr, $($arg:tt)+) => (log!(target: $target, $crate::Level::Info, $($arg)+));
130+
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Info, $($arg)+));
131131

132132
// info!("a {} event", "log")
133-
($($arg:tt)+) => (log!($crate::Level::Info, $($arg)+))
133+
($($arg:tt)+) => ($crate::log!($crate::Level::Info, $($arg)+))
134134
}
135135

136136
/// Logs a message at the debug level.
@@ -148,14 +148,14 @@ macro_rules! info {
148148
/// debug!(target: "app_events", "New position: x: {}, y: {}", pos.x, pos.y);
149149
/// # }
150150
/// ```
151-
#[macro_export(local_inner_macros)]
151+
#[macro_export]
152152
macro_rules! debug {
153153
// debug!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
154154
// debug!(target: "my_target", "a {} event", "log")
155-
(target: $target:expr, $($arg:tt)+) => (log!(target: $target, $crate::Level::Debug, $($arg)+));
155+
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Debug, $($arg)+));
156156

157157
// debug!("a {} event", "log")
158-
($($arg:tt)+) => (log!($crate::Level::Debug, $($arg)+))
158+
($($arg:tt)+) => ($crate::log!($crate::Level::Debug, $($arg)+))
159159
}
160160

161161
/// Logs a message at the trace level.
@@ -175,14 +175,14 @@ macro_rules! debug {
175175
/// if pos.y >= 0.0 { "positive" } else { "negative" });
176176
/// # }
177177
/// ```
178-
#[macro_export(local_inner_macros)]
178+
#[macro_export]
179179
macro_rules! trace {
180180
// trace!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
181181
// trace!(target: "my_target", "a {} event", "log")
182-
(target: $target:expr, $($arg:tt)+) => (log!(target: $target, $crate::Level::Trace, $($arg)+));
182+
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Trace, $($arg)+));
183183

184184
// trace!("a {} event", "log")
185-
($($arg:tt)+) => (log!($crate::Level::Trace, $($arg)+))
185+
($($arg:tt)+) => ($crate::log!($crate::Level::Trace, $($arg)+))
186186
}
187187

188188
/// Determines if a message logged at the specified level in that module will
@@ -211,7 +211,7 @@ macro_rules! trace {
211211
/// # fn expensive_call() -> Data { Data { x: 0, y: 0 } }
212212
/// # fn main() {}
213213
/// ```
214-
#[macro_export(local_inner_macros)]
214+
#[macro_export]
215215
macro_rules! log_enabled {
216216
(target: $target:expr, $lvl:expr) => {{
217217
let lvl = $lvl;
@@ -220,49 +220,7 @@ macro_rules! log_enabled {
220220
&& $crate::__private_api_enabled(lvl, $target)
221221
}};
222222
($lvl:expr) => {
223-
log_enabled!(target: __log_module_path!(), $lvl)
224-
};
225-
}
226-
227-
// The log macro above cannot invoke format_args directly because it uses
228-
// local_inner_macros. A format_args invocation there would resolve to
229-
// $crate::format_args which does not exist. Instead invoke format_args here
230-
// outside of local_inner_macros so that it resolves (probably) to
231-
// core::format_args or std::format_args. Same for the several macros that
232-
// follow.
233-
//
234-
// This is a workaround until we drop support for pre-1.30 compilers. At that
235-
// point we can remove use of local_inner_macros, use $crate:: when invoking
236-
// local macros, and invoke format_args directly.
237-
#[doc(hidden)]
238-
#[macro_export]
239-
macro_rules! __log_format_args {
240-
($($args:tt)*) => {
241-
format_args!($($args)*)
242-
};
243-
}
244-
245-
#[doc(hidden)]
246-
#[macro_export]
247-
macro_rules! __log_module_path {
248-
() => {
249-
module_path!()
250-
};
251-
}
252-
253-
#[doc(hidden)]
254-
#[macro_export]
255-
macro_rules! __log_file {
256-
() => {
257-
file!()
258-
};
259-
}
260-
261-
#[doc(hidden)]
262-
#[macro_export]
263-
macro_rules! __log_line {
264-
() => {
265-
line!()
223+
$crate::log_enabled!(target: $crate::__private_api::module_path!(), $lvl)
266224
};
267225
}
268226

@@ -271,7 +229,7 @@ macro_rules! __log_line {
271229
macro_rules! __log_key {
272230
// key1 = 42
273231
($($args:ident)*) => {
274-
stringify!($($args)*)
232+
$crate::__private_api::stringify!($($args)*)
275233
};
276234
// "key1" = 42
277235
($($args:expr)*) => {

0 commit comments

Comments
 (0)