Skip to content

Lint path or import used in macro #9104

@i509VCB

Description

@i509VCB

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 {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions