-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
A-diagnosticsArea: Error and warning messages generated by Cargo itself.Area: 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`Category: 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 reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review
Description
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` existsThe "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
cargo/src/cargo/util/toml_mut/manifest.rs
Line 686 in 6d1bd93
| 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: fooNotes
Option 2 is closer to the compiler's message if you typo a variable name.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Error and warning messages generated by Cargo itself.Area: 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`Category: 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 reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or review