rust-lang / rust-lang/rust

Empty super::{} and self::{} imports gives an error.

Open
#119,776 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Code
mod foo {
    use super::{};
}
Current output
error[E0432]: unresolved import `super`
 --> src/lib.rs:2:9
  |
2 |     use super::{};
  |         ^^^^^^^^^ no `super` in the root

warning: unused import: `super::{}`
 --> src/lib.rs:2:9
  |
2 |     use super::{};
  |         ^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
Desired output
warning: unused import: `super::{}`
 --> src/lib.rs:2:9
  |
2 |     use super::{};
  |         ^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
Rationale and extra context

The same problem exists with an empty use self::{}; import.

There is no reason for empty self and super imports gives an error when empty crate::{}, some_crate::{} and path::to::a::module::{} imports are perfectly valid. The compiler should of course emit a warning.

If they should be forbidden nonetheless, the error message could be clearer.

It should be noted that the following code if perfectly valid:

mod bar {}
mod foo {
    use super::bar::{};
}
use self::bar::{};

I obtained such a code with empty super imports with macros.

Other cases

No response

Rust Version
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
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 examples in src/lib.rs with rustc 1.75.0, comparing empty super::{} and self::{} imports with the valid crate::{} and nested-path cases. Trace the compiler handling for these imports and add a regression check showing that empty self and super imports produce only the unused-import warning, not an unresolved-import error.

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.