-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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