Skip to content

Warn against mod lib; in main.rs #56314

Open
@Kimundi

Description

@Kimundi

Right now this is possible and compiles without warning:

Given a cargo crate with name "foo":

// src/lib.rs
// src/main.rs

mod lib;
fn main() {}

... even though we now have duplicated code in the library "foo" and the submodule "lib"

This can be confusing for a beginner because the code can still compile or just breaks "late" depending on what you do:

// src/lib.rs

pub struct Foo;
// src/main.rs

mod lib;

// either of those work (though not at the same time):
use foo::Foo;
use crate::lib::Foo;

fn main() {}

cargo or rustc should detect if we use lib.rs as a submodule, and warn or error against it.


This issue assumes 2018 edition without uniform paths syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.T-langRelevant to the language 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