Skip to content

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

@narpfel

Description

@narpfel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions