Skip to content

Lint for redundant package alias in Cargo.toml #16997

@notpeter

Description

@notpeter

What it does

Cargo will happily accept the following:

[dependencies]
foo = { package = "foo", version = "1.0" }

Where package declaration is redundant as crate name foo in package and the new alias foo are the same.

The lint would just suggesting removing package = "foo" key.
Similar to how rust fmt will convert use foo as foo; to use foo;

Advantage

  • Remove a no-op directive

I encountered this in the wild here. This crashes renovate (their bug, not Cargo's problem).

Drawbacks

None? I can't imagine a situation where this wasn't a no-op.

Example

[dependencies]
foo = { package = "foo", version = "1.0" }

[dependencies.bar]
version = "1.0"
package = "bar"

Could be written as:

[dependencies]
foo = { version = "1.0" }
foo = "1.0"

[dependencies.bar]
version = "1.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-new-lintArea: new lintS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions