rust-lang / rust-lang/rust-clippy

`self_named_module_files` does not find self named module files

Open
#8,094 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The self_named_module_files lint fails to trigger an error in a crate with this file structure:

.
├── Cargo.lock
├── Cargo.toml
└── src
   ├── lib.rs
   ├── outer
   │  └── inner.rs
   └── outer.rs

I initially thought the issue might be related to the inner module being annotated with #[cfg(test)], but that's not needed to cause the false negative.

Lint Name

self_named_module_files

Reproducer

I tried this code:

// src/lib.rs
#![deny(clippy::self_named_module_files)]
pub mod outer;
// src/outer.rs
pub mod inner;
// src/outer/inner.rs
pub struct Foo;

I expected to see this happen: The self_named_module_files lint causes an error when cargo clippy is run.

Instead, this happened: No lints caused any errors.

Version
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

The same issue also occurs on the latest nightly at the time of filing this issue:

rustc 1.59.0-nightly (0b6f079e4 2021-12-07)
binary: rustc
commit-hash: 0b6f079e4987ded15c13a15b734e7cfb8176839f
commit-date: 2021-12-07
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0

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

Reproduce the issue with src/lib.rs, src/outer.rs, and src/outer/inner.rs, using the self_named_module_files lint and cargo clippy. Then trace the lint's module-file handling and add coverage for this structure; done means cargo clippy reports the expected lint error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.