Skip to content

False positive when name is not the same as the dir #10271

@TimeEngineer

Description

@TimeEngineer

Summary

Let's say you have a project:

api/
|- foo/
    |- src/
        |- lib.rs
    |- Cargo.toml
src/
|- foo.rs
|- lib.rs
Cargo.toml
# /Cargo.toml
[package]
name = "false_positive"
version = "0.1.0"
edition = "2021"

[workspace]
members = ["api/*"]

[dependencies]
renamed_foo = { path = "api/foo" }
// /src/lib.rs
mod foo;

pub use foo::*;
pub use renamed_foo::*;
# /api/foo/Cargo.toml
[package]
name = "renamed_foo" # Not the same name as the dir
version = "0.1.0"
edition = "2021"

[dependencies]
// /api/foo/src/lib.rs
// Note: This is important that this file is not empty.
pub fn function() {}

Lint Name

clippy::self-named-module-files

Reproducer

I tried to run with:

cargo clippy -- --deny=clippy::self_named_module_files

I saw this happen:

error: `mod.rs` files are required, found `src/foo.rs`
 --> src/foo.rs:0:1
  |
  |
  = help: move `src/foo.rs` to `src/foo/mod.rs`
  = note: requested on the command line with `-D clippy::self-named-module-files`

error: could not compile `false_positive` due to previous error

I expected to see this happen:

no error

Version

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.2

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions