rust-lang / rust-lang/rust-clippy

allow(single_component_path_imports) does not apply to imports in annotated modules.

Open
#9,382 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

This might be somewhat similar to some existing issues so if it would be preferable to comment on one of them and close this one that's fine, but I didn't see it specifically.

I have some automatically generated code which triggers the single_component_path_imports lint. I'm not opposed to the lint in general, but I'd rather keep the automatically generated code unedited by hand. I thought I could just add the allow(...) attribute to the module declaration, but it doesn't seem to apply recursively to the code in the declared module.

Reproducer

I tried this code:

#[allow(unused_imports)]
#[allow(clippy::single_component_path_imports)]
mod test {
    use anyhow;
}

I expected to see this happen: The lint would be suppressed.

Instead, this happened: The lint warning continues to appear.

Version
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the annotated-module example and tracing how the single_component_path_imports lint handles module-level allow attributes. Done means the lint is suppressed for the import inside the annotated module, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.