Skip to content

special_module_name triggered for a directory module #104161

Open
@Tuetuopay

Description

@Tuetuopay

Summary

I have a bin crate that has at its source root a directory named lib/ for a module named, well, lib.

When upgrading to Rust 1.65, I get a new lint warning telling me that there is a "module declaration for lib.rs" which is wrong because I have no lib.rs.

I know that it's a bad name for a module, and I'll probably rename it, but I wanted to let you know!

Lint Name

special_module_name

Reproducer

I tried this code:

# main.rs
mod lib;

fn main() {
    lib::foo();
}

# lib/mod.rs
pub fn foo() {
    println!("foo!");
}

I saw this happen:

warning: found module declaration for lib.rs
  --> api/src/main.rs:1:1
   |
 1 | mod lib;
   | ^^^^^^^^
   |
   = note: `#[warn(special_module_name)]` on by default
   = note: lib.rs is the root of this crate's library target
   = help: to refer to it from other targets, use the library's name as the path

I expected to see this happen: no lint warning.

Version

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-special_module_nameLint: special_module_nameT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions