Skip to content

single_component_path_imports: False positive for exporting macros within crate #7106

Closed
@cherryblossom000

Description

@cherryblossom000

Lint name: single_component_path_imports

I tried this code:

mod a {
    macro_rules! foo {
        () => {
            println!("foo")
        };
    }
    // This use statement is required to allow non-parent modules in the same crate to use it,
    // while preventing other crates from using it
    pub(crate) use foo;
}

// The rest isn't necessary to reproduce but it shows why it's a false positive
mod b {
    use super::a;
    pub(crate) fn bar() {
        a::foo!();
    }
}

fn main() {
    b::bar();
}

I expected to see this happen: no lint warnings

Instead, this happened:

warning: this import is redundant
 --> src/main.rs:9:5
  |
9 |     pub(crate) use foo;
  |     ^^^^^^^^^^^^^^^^^^^ help: remove it entirely
  |
  = note: `#[warn(clippy::single_component_path_imports)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports

Note that I cannot use #[macro_use] in this scenario because b is a sibling module of a, not a parent, so you can't declare #[macro_use] mod a; in b.

Meta

  • cargo clippy -V: clippy 0.1.51 (2fd73fab 2021-03-23)
  • rustc -Vv:
    rustc 1.51.0 (2fd73fabe 2021-03-23)
    binary: rustc
    commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
    commit-date: 2021-03-23
    host: x86_64-apple-darwin
    release: 1.51.0
    LLVM version: 11.0.1
    

Metadata

Metadata

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions