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 macros used in the same module #7923

Closed
SabrinaJewson opened this issue Nov 3, 2021 · 2 comments · Fixed by #8537
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing 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

@SabrinaJewson
Copy link
Contributor

SabrinaJewson commented Nov 3, 2021

Lint name: single_component_path_imports

I tried this code:

m!();
macro_rules! m { () => {} }
use m;

I expected to see this happen: Clippy would not warn

Instead, this happened: Clippy showed this warning:

warning: this import is redundant
 --> src/lib.rs:3:1
  |
3 | use m;
  | ^^^^^^ 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

Meta

Rust version (rustc -Vv):

rustc 1.58.0-nightly (29b124802 2021-10-25)
binary: rustc
commit-hash: 29b1248025b19bd132c8047fc710ea9314b9b76b
commit-date: 2021-10-25
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

cc #7106

@rustbot label +I-suggestion-causes-error

@SabrinaJewson SabrinaJewson 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 Nov 3, 2021
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Nov 3, 2021
@BartMassey
Copy link

Just ran into this.

pub mod m {
    pub fn f() {
        super::g!();
    }
}

macro_rules! g {
    () => {
        println!("hello");
    };
}
use g;

As noted, following Clippy's suggestion fails compilation. g needs to be accessible inside m and there's no other way (that I am aware of) to make that possible— except #[macro_export], which will make it visible outside the containing crate.

It appears that single_component_path_imports is global-only and cannot be suppressed on a case-by-case basis. Compare with #7290.

@xFrednet
Copy link
Member

@rustbot claim

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 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.

4 participants