rust-lang / rust-lang/rust

importing an item into the module it was defined in is described as "multiple definitions"

Open
#131,115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
pub struct St;
use St;
Current output
error[E0255]: the name `St` is defined multiple times
 --> src/lib.rs:2:5
  |
1 | pub struct St;
  | -------------- previous definition of the type `St` here
2 | use St;
  |     ^^ `St` reimported here
  |
  = note: `St` 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
  |
2 | use St as OtherSt;
  |        ++++++++++

warning: unused import: `St`
 --> src/lib.rs:2:5
  |
2 | use St;
  |     ^^
  |
  = note: `#[warn(unused_imports)]` on by default
Desired output
error[E0255]: the name `St` is defined multiple times
 --> src/lib.rs:2:5
  |
1 | pub struct St;
  | -------------- previous definition of the type `St` here
2 | use St;
  |     ^^ `St` reimported here
  |
  = note: `St` must be defined only once in the type namespace of this module
help: remove the import
  |
2 | use St;
  | ------

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

No response

Other cases

this should also be handled for circular reimports:

pub use m::St;
mod m {
    pub struct St;
    use crate::St;
}
Rust Version

rustc 1.83.0-nightly (2bd1e894e 2024-09-26)
binary: rustc
commit-hash: 2bd1e894efde3b6be857ad345914a3b1cea51def
commit-date: 2024-09-26
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

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

Start by reproducing the direct reimport example in src/lib.rs with the reported rustc version and compare the current and desired diagnostics. Check the circular reimport example as well; done means both cases suggest removing the import and retain the existing error and warning details.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.