diff --git a/src/cargo/util/toml_mut/manifest.rs b/src/cargo/util/toml_mut/manifest.rs index e166a24f2be..98033531e3a 100644 --- a/src/cargo/util/toml_mut/manifest.rs +++ b/src/cargo/util/toml_mut/manifest.rs @@ -9,6 +9,7 @@ use anyhow::Context as _; use super::dependency::Dependency; use crate::core::dependency::DepKind; use crate::core::{FeatureValue, Features, Workspace}; +use crate::util::closest; use crate::util::interning::InternedString; use crate::{CargoResult, GlobalContext}; @@ -381,6 +382,13 @@ impl LocalManifest { } } None => { + let names = parent_table + .as_table_like() + .map(|t| t.iter()) + .into_iter() + .flatten(); + let alt_name = closest(name, names.map(|(k, _)| k), |k| k).map(|n| n.to_owned()); + // Search in other tables. let sections = self.get_sections(); let found_table_path = sections.iter().find_map(|(t, i)| { @@ -393,6 +401,7 @@ impl LocalManifest { name, table_path.join("."), found_table_path, + alt_name.as_deref(), )); } } @@ -605,10 +614,13 @@ fn non_existent_dependency_err( name: impl std::fmt::Display, search_table: impl std::fmt::Display, found_table: Option, + alt_name: Option<&str>, ) -> anyhow::Error { let mut msg = format!("the dependency `{name}` could not be found in `{search_table}`"); if let Some(found_table) = found_table { msg.push_str(&format!("; it is present in `{found_table}`",)); + } else if let Some(alt_name) = alt_name { + msg.push_str(&format!("; dependency `{alt_name}` exists",)); } anyhow::format_err!(msg) } diff --git a/tests/testsuite/cargo_remove/invalid_dep/in b/tests/testsuite/cargo_remove/invalid_dep/in deleted file mode 120000 index 7fd0ba5ebcc..00000000000 --- a/tests/testsuite/cargo_remove/invalid_dep/in +++ /dev/null @@ -1 +0,0 @@ -../remove-basic.in/ \ No newline at end of file diff --git a/tests/testsuite/cargo_remove/invalid_dep/in/Cargo.toml b/tests/testsuite/cargo_remove/invalid_dep/in/Cargo.toml new file mode 100644 index 00000000000..1a373b7dae4 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/in/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "cargo-remove-test-fixture" +version = "0.1.0" +edition = "2015" + +[[bin]] +name = "main" +path = "src/main.rs" + +[build-dependencies] +semver = "0.1.0" + +[dependencies] +invalid-dependency-name = "0.6" +docopt = "0.6" +semver = "0.1" + +[dev-dependencies] +serde = "1.0.90" + +[features] +std = ["serde/std", "semver/std"] diff --git a/tests/testsuite/cargo_remove/invalid_dep/in/src/lib.rs b/tests/testsuite/cargo_remove/invalid_dep/in/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/testsuite/cargo_remove/invalid_dep/in/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/testsuite/cargo_remove/invalid_dep/mod.rs b/tests/testsuite/cargo_remove/invalid_dep/mod.rs index 50eb967f2d4..40da2984207 100644 --- a/tests/testsuite/cargo_remove/invalid_dep/mod.rs +++ b/tests/testsuite/cargo_remove/invalid_dep/mod.rs @@ -9,11 +9,9 @@ use cargo_test_support::Project; #[cargo_test] fn case() { cargo_test_support::registry::init(); - cargo_test_support::registry::Package::new("clippy", "0.4.0+my-package").publish(); + cargo_test_support::registry::Package::new("invalid-dependency-name", "0.6.2+my-package") + .publish(); cargo_test_support::registry::Package::new("docopt", "0.6.2+my-package").publish(); - cargo_test_support::registry::Package::new("regex", "0.1.1+my-package").publish(); - cargo_test_support::registry::Package::new("rustc-serialize", "0.4.0+my-package").publish(); - cargo_test_support::registry::Package::new("toml", "0.1.1+my-package").publish(); cargo_test_support::registry::Package::new("semver", "0.1.1") .feature("std", &[]) .publish(); diff --git a/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml b/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml index fe49a10648d..1a373b7dae4 100644 --- a/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml +++ b/tests/testsuite/cargo_remove/invalid_dep/out/Cargo.toml @@ -11,14 +11,11 @@ path = "src/main.rs" semver = "0.1.0" [dependencies] +invalid-dependency-name = "0.6" docopt = "0.6" -rustc-serialize = "0.4" semver = "0.1" -toml = "0.1" -clippy = "0.4" [dev-dependencies] -regex = "0.1.1" serde = "1.0.90" [features] diff --git a/tests/testsuite/cargo_remove/invalid_dep/stderr.term.svg b/tests/testsuite/cargo_remove/invalid_dep/stderr.term.svg index 3b7fb2b807d..5eecfe5e7da 100644 --- a/tests/testsuite/cargo_remove/invalid_dep/stderr.term.svg +++ b/tests/testsuite/cargo_remove/invalid_dep/stderr.term.svg @@ -1,4 +1,4 @@ - +