rust-lang / rust-lang/rust-clippy
wildcard_imports breaks code with suggested use stmt
Open
Nobody has claimed this yet.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
.
Lint Name
wildcard_imports
Reproducer
I tried this code:
// Minimized case from #62767.
mod m {
pub enum Same {
Same,
}
}
use m::*;
// The variant `Same` introduced by this import is also considered when resolving the prefix
// `Same::` during import validation to avoid effects similar to time travel (#74556).
use Same::Same;
// Case from #74556.
mod foo {
pub mod bar {
pub mod bar {
pub fn foobar() {}
}
}
}
use foo::*;
use bar::bar;
use bar::foobar;
fn main() {}
I saw this happen:
cargo clippy --fix -- -Aclippy::all -Wclippy::wildcard_imports
Checking clpy v0.1.0 (/tmp/clpy)
warning: failed to automatically apply fixes suggested by rustc to crate `clpy`
after fixes were automatically applied the compiler reported errors within these files:
* src/main.rs
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error[E0252]: the name `bar` is defined multiple times
--> src/main.rs:24:5
|
23 | use foo::bar;
| -------- previous import of the module `bar` here
24 | use bar::bar;
| ^^^^^^^^ `bar` reimported here
|
= note: `bar` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
24 | use bar::bar as other_bar;
| ~~~~~~~~~~~~~~~~~~~~~
warning: unused import: `m::Same`
--> src/main.rs:8:5
|
8 | use m::Same;
| ^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `bar::bar`
--> src/main.rs:24:5
|
24 | use bar::bar;
| ^^^^^^^^
error: aborting due to previous error; 2 warnings emitted
For more information about this error, try `rustc --explain E0252`.
Original diagnostics will follow.
warning: unused import: `Same::Same`
--> src/main.rs:12:5
|
12 | use Same::Same;
| ^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `bar::foobar`
--> src/main.rs:26:5
|
26 | use bar::foobar;
| ^^^^^^^^^^^
warning: enum `Same` is never used
--> src/main.rs:3:14
|
3 | pub enum Same {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: function `foobar` is never used
--> src/main.rs:18:20
|
18 | pub fn foobar() {}
| ^^^^^^
warning: usage of wildcard import
--> src/main.rs:8:5
|
8 | use m::*;
| ^^^^ help: try: `m::Same`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
= note: requested on the command line with `-W clippy::wildcard-imports`
warning: usage of wildcard import
--> src/main.rs:23:5
|
23 | use foo::*;
| ^^^^^^ help: try: `foo::bar`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
warning: `clpy` (bin "clpy" test) generated 6 warnings (run `cargo fix --bin "clpy" --tests` to apply 4 suggestions)
warning: `clpy` (bin "clpy") generated 6 warnings (6 duplicates)
Finished dev [unoptimized + debuginfo] target(s) in 1.11s
I expected to see this happen:
Version
rustc 1.67.0-nightly (c5d82ed7a 2022-11-19)
binary: rustc
commit-hash: c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b
commit-date: 2022-11-19
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
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.
Research direction
Start by reproducing the issue with the shown cargo clippy --fix -- -Aclippy::all -Wclippy::wildcard_imports command and the wildcard_imports lint example. Trace how the lint's suggested imports are applied, then verify that fixing the wildcard imports no longer produces the reported E0252 error for the reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100