Skip to content

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

Open
@JeanCASPAR

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-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