You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check for relative paths (such as core::ops::BitOr) being used in macros.
When writing declarative macros, one should always refer to items using their absolute path (paths starting with :: or using $crate or be keywords such as Self). That is because users might declare a module with the same name as the first component of the path and thus change the meaning of the macro.
Advantage
This change prevents macros from changing their meaning depending on the context:
This code fails to compile, because the path core::ops::BitOr is relative and thus the custom core module defined in mod bar is used instead of the core crate.
Drawbacks
Increase verbosity and thus decrease readability of declarative macros.
What it does
Check for relative paths (such as
core::ops::BitOr
) being used in macros.When writing declarative macros, one should always refer to items using their absolute path (paths starting with
::
or using$crate
or be keywords such asSelf
). That is because users might declare a module with the same name as the first component of the path and thus change the meaning of the macro.Advantage
This change prevents macros from changing their meaning depending on the context:
This code fails to compile, because the path
core::ops::BitOr
is relative and thus the customcore
module defined inmod bar
is used instead of thecore
crate.Drawbacks
Increase verbosity and thus decrease readability of declarative macros.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: