Skip to content

add a warning when compiling a user crate named core #7760

@tanriol

Description

@tanriol

Problem: I've seen several times in Gitter/Matrix channels that people had weird errors because they had a dependency on their own crate named core that shadowed the default and caused import errors in proc macros that generated code assuming the standard core crate.

This is a mistake that's easy to make for a newcomer (core is an obvious choice for a base crate others depend on, and, unlike for std, it's not obvious that Rust uses this crate name for its own purposes) and causes strange-looking errors ("it cannot find something that's not even mentioned in its docs? how could it get that broken?").

Suggested solution: add a warning when compiling a crate named core telling the user that the core crate name is used internally by Rust and one shall not use it for their own crates unless they're making an alternate standard library.

Possible alternative: make this a deny-by-default lint in rustc instead to actually provide the user with a way of saying "yes, I really meant to call this crate core" and silencing the warning.

Possible alternative 2: warn on explicitly depending on core from Cargo.toml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-new-lintArea: new lintC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions