rust-lang / rust-lang/rust

`unqualified_local_imports` lint does not trigger on import of local reimport of foreign item

Open
#138,908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(unqualified_local_imports)]

#![allow(unused)]
#![warn(unqualified_local_imports)]

use memchr::memmem::Prefilter;

mod m {
    use super::*;
    use Prefilter::*;
}
Current output
<no warning>
Desired output
Compiling playground v0.0.1 (/playground)
warning: `use` of a local item without leading `self::`, `super::`, or `crate::`
  --> src/lib.rs:10:9
   |
10 |     use Prefilter::*;
   |         ^^^^^^^^^
   |
note: the lint level is defined here
  --> src/lib.rs:4:9
   |
4  | #![warn(unqualified_local_imports)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `playground` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.90s
Rationale and extra context

I don’t know if this is intentional, but it surprised me that the lint would not trigger for an import whose first path segment is not super, self, crate or the name of an external crate.

When using rustfmt with group_imports = "StdExternalCrate", use Prefilter::* will be put into the “external” section by rustfmt, even though it’s (from the point of view of the module) a local name.

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=37d2c33bbaf85ecf5d598009ac07ae3e
Playground link with reimport of local type: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=b8ab3ad23c3e4851c62f118d24d8bf83

Tracking issue: #138299


This simpler case also does not trigger the lint, but in this case, it’s easier to see where the imported item comes from than in the case with use super::*;, where the inner module can be in a different file than the original import of the item, but even in this case sorting the imports will probably make the code harder to read by moving both imports further away from each other.

#![feature(unqualified_local_imports)]

#![allow(unused)]
#![warn(unqualified_local_imports)]

use memchr::memmem::Prefilter;

use Prefilter::*;

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=9a73ab3b4b2a256d3dc3de46d009c15e

Other cases

Rust Version
$ rustc --version --verbose
rustc 1.87.0-nightly (aa8f0fd71 2025-03-23)
binary: rustc
commit-hash: aa8f0fd7163a2f23aa958faed30c9c2b77b934a5
commit-date: 2025-03-23
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.1
Anything else?

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

Reproduce the issue with the Rust code examples and the linked Playground cases, using the reported nightly version as a baseline. Start by tracing the unqualified_local_imports lint behavior for reimported local items, then add coverage for the shown Prefilter cases and verify that the expected warning is emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.