Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

single_component_path_imports: False positive for exporting macros within crate #7106

Closed
cherryblossom000 opened this issue Apr 18, 2021 · 1 comment · Fixed by #7120
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@cherryblossom000
Copy link
Contributor

cherryblossom000 commented Apr 18, 2021

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
    
@cherryblossom000 cherryblossom000 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 18, 2021
@giraffate giraffate added good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Apr 19, 2021
@cherryblossom000
Copy link
Contributor Author

I'll have a go at this.

@rustbot claim

bors added a commit that referenced this issue Apr 22, 2021
`single_component_path_imports`: ignore `pub(crate) use some_macro;`

Fixes #7106

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Ignore exporting a macro within a crate using `pub(crate) use some_macro;` for [`single_component_path_imports`]
@bors bors closed this as completed in b48699e Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants