rust-clippy
rust-clippy copied to clipboard
Lint path or import used in macro
What it does
Lint any instances of paths to items or use statements which do not use $crate
or global paths (such as ::std::vec::Vec
)
Lint Name
macro_use_path
Category
correctness
Advantage
- Since imports and paths in macros are unhygienic, you should use
$crate
or global paths. - This will make macros used by other crates less likely to fail to compile.
Drawbacks
- Internal macros may wish to avoid this requirement
Example
pub trait Delegate {}
#[macro_export]
macro_rules! impl_delegate {
($ty: ty) => {
impl Delegate for $ty {}
}
}
Could be written as:
pub trait Delegate {}
#[macro_export]
macro_rules! impl_delegate {
impl $crate::Delegate for $ty {}
}
Discussion on zulip about this lint is going to be a challenge given the macro is not enough information (you need to look at the expanded macro to determine the AST.