rust-lang / rust-lang/rust-clippy
Lint against recursive imports (paths that start at a previous import)
@karabacakcan is already working on this.
Since Jul 19, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
When reading a use declaration, you have to know what the first component refers to. If it starts with :: or crate, it's definitely an absolute path; if it starts with self or super, it's definitely a relative path. Otherwise, there are three choices:
- it's an external crate
- it's a submodule* declared in this file
- it's something else I've already imported
* okay technically it could be a type
Usually I can distinguish between (1) and (2), but with (3) all bets are off, whether it's from inside the current crate or from an external crate. (Some may disagree here and say "it's okay for current-crate imports" or "it's okay for external-crate imports".) I'd rather lint against them.
Exceptions (should not lint on these):
- the recursive
useis not in the same scope as the one it references - (maybe?) the referenced
useispubbut the recursive one is not -pub useis similar to declaring a submodule, so it's a "faux (2)" case
Advantage
- Easier for a human to figure out a
usedeclaration - Fewer total
usedeclarations, if you're okay withself
Drawbacks
- Longer import lines
- Special rule for
usethat doesn't apply to the rest of the code (where it is common to use relative paths often and absolute paths occasionally).
Example
use external_crate::foo;
use foo::Bar;
Could be written as:
use external_crate::foo;
use external_crate::foo::Bar;
or
use external_crate::foo::{self, Bar};
Comparison with existing lints
- #14246 imposes a stronger style than this proposal (
selfrequired even for submodules) but would solve the problem - #12796 is stronger still (
crate-absolute paths required even for submodules)
Additional Context
No response
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.
Assessment
This issue has not been assessed yet.