Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
narpfel opened this issue Mar 24, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@narpfel
Copy link
Contributor

narpfel commented Mar 24, 2025

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

@narpfel narpfel added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant