Exported macro uses crate:: instead of $crate::
ID |
rust.correctness.crate_instead_crate_macro_definitions |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Api Misuse |
Language |
Rust |
Description
Inside an exported macro, crate:: resolves in the crate that invokes the macro, not the one that defines it, so the path breaks — or silently resolves to something else — for every downstream user. Write $crate:: to refer to the defining crate.
Rationale
Inside an exported macro, crate:: resolves in the crate that invokes the macro, not the one that defines it, so the path breaks — or silently resolves to something else — for every downstream user. Write $crate:: to refer to the defining crate.
The following code illustrates the pattern detected by this rule:
pub fn helper(value: u32) -> u32 {
value
}
#[macro_export]
macro_rules! wrap_value {
($v:expr) => {
// FLAGGED: Exported macro uses `crate::` instead of `$crate::`
crate::helper($v)
};
}