rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.25k stars 1.52k forks source link

`self_named_module_files` does trigger for `lib.rs` for a crate inside of a workspace under `lib/` #11916

Open TimDiekmann opened 9 months ago

TimDiekmann commented 9 months ago

Summary

Reproduction repository: https://github.com/TimDiekmann/self_named_module_files-false-positive

Given the following workspace layout:

.
├── Cargo.toml
└── lib
    └── test-crate
        ├── Cargo.toml
        └── src
            └── lib.rs

4 directories, 3 files

if test-crate is part of the outer workspace and enables the self_named_module_files this will trigger the lint on lib.rs

Lint Name

self_named_module_files

Reproducer

I tried this code:

#![deny(clippy::self_named_module_files)]

I saw this happen:

error: `mod.rs` files are required, found `lib/test-crate/src/lib.rs`
  |
  = help: move `lib/test-crate/src/lib.rs` to `lib/test-crate/src/lib/mod.rs`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#self_named_module_files
note: the lint level is defined here
 --> lib/test-crate/src/lib.rs:1:9
  |
1 | #![deny(clippy::self_named_module_files)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `test-crate` (lib) due to previous error

I expected to see this happen: The lint should not trigger

Version

rustc 1.76.0-nightly (90e321d82 2023-12-02)
binary: rustc
commit-hash: 90e321d82a0a9c3d0e3f180d4d17541b729072e0
commit-date: 2023-12-02
host: aarch64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.5

Additional Labels

No response

silwol commented 3 months ago

Stumbled over the same issue. It appears this is caused by having at least one component in the path which is equal to the module name, doesn't have to be lib. Important sidenote: the path name is relevant, not the crate name.

My reproducer project for this issue contains a module file crates/example/src/example.rs, while the crate name inside crates/example/Cargo.toml is "some-example".