rust-lang / rust-lang/rust-clippy
FP single_component_path_imports
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name:
single_component_path_imports
I tried this code:
#[cfg(feature = "log")]
use log;
mod foo {
use crate::log::warn;
pub fn bar() {
warn!("bar");
}
}
pub fn bar() {
foo::bar()
}
(I think it doesn't matter whether the feature log is turned on or off.)
I expected to see this happen: no warning, since the log import is used in an inner module.
Instead, this happened:
warning: this import is redundant
--> src/lib.rs:3:1
|
3 | use log;
| ^^^^^^^^ 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
cargo clippy -V: clippy 0.1.53 (42816d61 2021-04-24)rustc -Vv:rustc 1.53.0-nightly (42816d61e 2021-04-24) binary: rustc commit-hash: 42816d61ead7e46d462df997958ccfd514f8c21c commit-date: 2021-04-24 host: x86_64-apple-darwin release: 1.53.0-nightly LLVM version: 12.0.0
cc @ThibsG (re https://github.com/rust-lang/rust-clippy/pull/6905#event-4578609048)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Rust snippet with the single_component_path_imports lint enabled, then inspect the lint's implementation and existing tests. Done means the outer use log; import no longer produces a warning when the inner module uses crate::log::warn.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100