Resolving "ambiguous name" when reexporting macro
⚓ Rust 📅 2025-11-14 👤 surdeus 👁️ 4Hey!
I'm trying to initialize 2 loggers (as in log::Log), one as the default global logger, and another as an opt-in logger used by certain modules.
I'm trying for it to look like log::info!("..."); and an additional my_mod::info!("...");.
It kinda works with this snippet:
mod my_log {
#![allow(unused)]
use std::sync::OnceLock;
use log::Log;
pub static LOGGER: OnceLock<Box<dyn Log>> = OnceLock::new();
#[clippy::format_args]
macro_rules! debug {
($($arg:tt)+) => {
log::debug!(logger: crate::my_log::LOGGER.get().unwrap(), $($arg)+)
};
}
#[clippy::format_args]
macro_rules! info {
($($arg:tt)+) => {
log::info!(logger: crate::my_log::LOGGER.get().unwrap(), $($arg)+)
};
}
#[clippy::format_args]
macro_rules! warn {
($($arg:tt)+) => {
log::warn!(logger: crate::my_log::LOGGER.get().unwrap(), $($arg)+)
};
}
#[clippy::format_args]
macro_rules! error {
($($arg:tt)+) => {
log::error!(logger: crate::my_log::LOGGER.get().unwrap(), $($arg)+)
};
}
pub(crate) use debug;
pub(crate) use info;
pub(crate) use warn;
pub(crate) use error;
}
Unfortunately I get an error for pub(crate) use warn;:
error[E0659]: `warn` is ambiguous
--> my_bin/src/main.rs:91:20
|
91 | pub(crate) use warn;
| ^^^^ ambiguous name
|
= note: ambiguous because of a name conflict with a builtin attribute
= note: `warn` could refer to a built-in attribute
note: `warn` could also refer to the macro defined here
--> my_bin/src/main.rs:79:5
|
79 | / macro_rules! warn {
80 | | ($($arg:tt)+) => {
81 | | log::warn!(logger: crate::my_log::LOGGER.get().unwrap(), $($arg)+)
82 | | };
83 | | }
| |_____^
Is there a way to disambiguate and tell the compiler that I'm referring to the macro defined in the same module?
(Or, is there another way to export warn! as my_mod::warn!?)
2 posts - 1 participant
🏷️ Rust_feed