Skip to content

"mod lib" in lib.rs produces incorrect error message #36146

Open
@Riateche

Description

@Riateche

lib.rs:

mod a1;
mod lib;

a1.rs - empty file.

Error:

error: cannot declare a new module at this location
 --> src/lib.rs:1:5
  |
1 | mod a1;
  |     ^^
  |
note: maybe move this module `lib` to its own directory via `lib/mod.rs`
 --> src/lib.rs:1:5
  |
1 | mod a1;
  |     ^^
note: ... or maybe `use` the module `a1` instead of possibly redeclaring it
 --> src/lib.rs:1:5
  |
1 | mod a1;
  |     ^^

Error location and some of the messages incorrectly refer to a1 module instead of lib. Module a1 itself is declared correctly. If I write lib before a1, the error starts making more sense:

lib.rs:

mod lib;
mod a1;

Error:

error: cannot declare a new module at this location
 --> src/lib.rs:1:5
  |
1 | mod lib;
  |     ^^^
  |
note: maybe move this module `lib` to its own directory via `lib/mod.rs`
 --> src/lib.rs:1:5
  |
1 | mod lib;
  |     ^^^
note: ... or maybe `use` the module `lib` instead of possibly redeclaring it
 --> src/lib.rs:1:5
  |
1 | mod lib;
  |     ^^^

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-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