Skip to content

Error message when trying to remove a typo'd dependency could be clearer #16499

@Seercat3160

Description

@Seercat3160

Problem

When using cargo remove, specifying a dependency name that is not present in Cargo.toml results in an error message suggesting the "closest" package by name.

Currently, if foo is a dependency:

$ cargo remove fo
    Removing fo from dependencies
error: the dependency `fo` could not be found in `dependencies`; dependency `foo` exists

The "dependency foo exists" part is unclear, particularly if the crate name is longer and the typo in the command is not noticed right away.
It comes from

msg.push_str(&format!("; dependency `{alt_name}` exists",));

Proposed Solution

Option 1

Change the message to something such as "Did you mean...?"

$ cargo remove fo
    Removing fo from dependencies
error: the dependency `fo` could not be found in `dependencies`; Did you mean `foo`?

Option 2

Use closest_msg

$ cargo remove fo
    Removing fo from dependencies
error: the dependency `fo` could not be found in `dependencies`
help: a dependency with a similar name exists: foo

Notes

Option 2 is closer to the compiler's message if you typo a variable name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-addS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions