Skip to content

redundant-imports lint does not work in macro-defined modules #158400

Description

@mkroening

Similar to #158371, I found that the redundant_imports lint does not work in modules that are defined in any macros. This is especially relevant since this also affects cfg_if! and cfg_select! which are often used to define modules (e.g., #158252).

Interestingly, other lints seem to work just fine, so this seems specific to the work that redundant_imports needs to do to analyze imports.

Reproduction

lib.rs:

#![deny(redundant_imports)]

#[cfg(true)]
pub mod foo; // works

macro_rules! identity {
    ($($tt:tt)*) => {
        $($tt)*
    };
}

identity! {
    // pub mod foo; // does not work
}

cfg_if::cfg_if! {
    if #[cfg(true)] {
        // pub mod foo; //does not work
    }
}

cfg_select! {
    _ => {
        // pub mod foo; // does not work
    }
}

foo.rs:

use std::option::Option::None;
pub fn foo() -> Option<i32> { None }

Command:

cargo check

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions