diff --git a/crates/resolver-tests/src/lib.rs b/crates/resolver-tests/src/lib.rs index efd9cebc6c6..8585abadac1 100644 --- a/crates/resolver-tests/src/lib.rs +++ b/crates/resolver-tests/src/lib.rs @@ -112,7 +112,8 @@ pub fn resolve_with_config_raw( for summary in self.list.iter() { let matched = match kind { QueryKind::Exact => dep.matches(summary), - QueryKind::Fuzzy => true, + QueryKind::Alternatives => true, + QueryKind::Normalized => true, }; if matched { self.used.insert(summary.package_id()); diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 4ecce02b5f0..ed981ebe37f 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -305,7 +305,7 @@ pub(super) fn activation_error( // Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing` // was meant. So we try asking the registry for a `fuzzy` search for suggestions. let candidates = loop { - match registry.query_vec(&new_dep, QueryKind::Fuzzy) { + match registry.query_vec(&new_dep, QueryKind::Alternatives) { Poll::Ready(Ok(candidates)) => break candidates, Poll::Ready(Err(e)) => return to_resolve_err(e), Poll::Pending => match registry.block_until_ready() { diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index 609793efa0f..9199b0e7143 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -588,7 +588,7 @@ fn get_latest_dependency( } MaybeWorkspace::Other(query) => { let possibilities = loop { - match registry.query_vec(&query, QueryKind::Fuzzy) { + match registry.query_vec(&query, QueryKind::Normalized) { std::task::Poll::Ready(res) => { break res?; } @@ -711,7 +711,7 @@ fn select_package( MaybeWorkspace::Other(query) => { let possibilities = loop { // Exact to avoid returning all for path/git - match registry.query_vec(&query, QueryKind::Exact) { + match registry.query_vec(&query, QueryKind::Normalized) { std::task::Poll::Ready(res) => { break res?; } @@ -938,7 +938,7 @@ fn populate_available_features( } let possibilities = loop { - match registry.query_vec(&query, QueryKind::Exact) { + match registry.query_vec(&query, QueryKind::Normalized) { std::task::Poll::Ready(res) => { break res?; } diff --git a/src/cargo/sources/directory.rs b/src/cargo/sources/directory.rs index 01c3c43302e..055b0004282 100644 --- a/src/cargo/sources/directory.rs +++ b/src/cargo/sources/directory.rs @@ -108,7 +108,8 @@ impl<'cfg> Source for DirectorySource<'cfg> { let packages = self.packages.values().map(|p| &p.0); let matches = packages.filter(|pkg| match kind { QueryKind::Exact => dep.matches(pkg.summary()), - QueryKind::Fuzzy => true, + QueryKind::Alternatives => true, + QueryKind::Normalized => dep.matches(pkg.summary()), }); for summary in matches.map(|pkg| pkg.summary().clone()) { f(IndexSummary::Candidate(summary)); diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index bbf6f056b16..fb70c34bac6 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -554,7 +554,8 @@ impl<'cfg> Source for PathSource<'cfg> { for s in self.packages.iter().map(|p| p.summary()) { let matched = match kind { QueryKind::Exact => dep.matches(s), - QueryKind::Fuzzy => true, + QueryKind::Alternatives => true, + QueryKind::Normalized => dep.matches(s), }; if matched { f(IndexSummary::Candidate(s.clone())) diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index f2f2bb037fa..474a4279ca4 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -792,7 +792,8 @@ impl<'cfg> Source for RegistrySource<'cfg> { .query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| { let matched = match kind { QueryKind::Exact => dep.matches(s.as_summary()), - QueryKind::Fuzzy => true, + QueryKind::Alternatives => true, + QueryKind::Normalized => true, }; if !matched { return; @@ -831,7 +832,7 @@ impl<'cfg> Source for RegistrySource<'cfg> { return Poll::Ready(Ok(())); } let mut any_pending = false; - if kind == QueryKind::Fuzzy { + if kind == QueryKind::Alternatives || kind == QueryKind::Normalized { // Attempt to handle misspellings by searching for a chain of related // names to the original name. The resolver will later // reject any candidates that have the wrong name, and with this it'll diff --git a/src/cargo/sources/source.rs b/src/cargo/sources/source.rs index dd6619e59a7..eac6e49c32e 100644 --- a/src/cargo/sources/source.rs +++ b/src/cargo/sources/source.rs @@ -179,7 +179,10 @@ pub enum QueryKind { /// Path/Git sources may return all dependencies that are at that URI, /// whereas an `Registry` source may return dependencies that have the same /// canonicalization. - Fuzzy, + Alternatives, + /// Match a denpendency in all ways and will normalize the package name. + /// Each source defines what normalizing means. + Normalized, } /// A download status that represents if a [`Package`] has already been diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/.cargo/config.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/.cargo/config.toml new file mode 100644 index 00000000000..77765fb2c26 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/.cargo/config.toml @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "./vendor" \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/Cargo.toml new file mode 100644 index 00000000000..cc2e9e1008a --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/src/lib.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/.cargo-checksum.json b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/.cargo-checksum.json new file mode 100644 index 00000000000..6b05e779481 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{}} \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/Cargo.toml new file mode 100644 index 00000000000..4ccb59396b6 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "aa" +version = "0.0.0" \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/src/lib.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/in/vendor/aa/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/mod.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/mod.rs new file mode 100644 index 00000000000..e4efa7b610d --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/mod.rs @@ -0,0 +1,35 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::current_dir; +use cargo_test_support::file; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + cargo_test_support::registry::alt_init(); + cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4") + .feature("clippy", &[]) + .feature("heapsize", &[]) + .feature("heapsize_impl", &[]) + .feature("nightly", &[]) + .feature("serde", &[]) + .feature("serde_impl", &[]) + .feature("serde_test", &[]) + .alternative(true) + .publish(); + + let project = Project::from_template(current_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("add") + .arg_line("linked_hash_map --registry alternative") + .current_dir(cwd) + .assert() + .success() + .stdout_matches(file!["stdout.log"]) + .stderr_matches(file!["stderr.log"]); + + assert_ui().subset_matches(current_dir!().join("out"), &project_root); +} diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/out/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/out/Cargo.toml new file mode 100644 index 00000000000..1fe8332c14e --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +linked-hash-map = { version = "0.5.4", registry = "alternative" } diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stderr.log b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stderr.log new file mode 100644 index 00000000000..004713758cc --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stderr.log @@ -0,0 +1,11 @@ + Updating `alternative` index +warning: translating `linked_hash_map` to `linked-hash-map` + Adding linked-hash-map v0.5.4 to dependencies + Features: + - clippy + - heapsize + - heapsize_impl + - nightly + - serde + - serde_impl + - serde_test diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stdout.log b/tests/testsuite/cargo_add/add_no_vendored_package_with_alter_registry/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/.cargo/config.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/.cargo/config.toml new file mode 100644 index 00000000000..77765fb2c26 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/.cargo/config.toml @@ -0,0 +1,5 @@ +[source.crates-io] +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "./vendor" \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/src/lib.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/.cargo-checksum.json b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/.cargo-checksum.json new file mode 100644 index 00000000000..6b05e779481 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{}} \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/Cargo.toml new file mode 100644 index 00000000000..4ccb59396b6 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "aa" +version = "0.0.0" \ No newline at end of file diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/src/lib.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/in/vendor/aa/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/mod.rs b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/mod.rs new file mode 100644 index 00000000000..e3ef32f9d63 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/mod.rs @@ -0,0 +1,23 @@ +use cargo_test_support::compare::assert_ui; +use cargo_test_support::current_dir; +use cargo_test_support::file; +use cargo_test_support::prelude::*; +use cargo_test_support::Project; + +#[cargo_test] +fn case() { + let project = Project::from_template(current_dir!().join("in")); + let project_root = project.root(); + let cwd = &project_root; + + snapbox::cmd::Command::cargo_ui() + .arg("add") + .arg_line("cbindgen") + .current_dir(cwd) + .assert() + .failure() + .stdout_matches(file!["stdout.log"]) + .stderr_matches(file!["stderr.log"]); + + assert_ui().subset_matches(current_dir!().join("out"), &project_root); +} diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/out/Cargo.toml b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stderr.log b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stderr.log new file mode 100644 index 00000000000..fbe4bffe918 --- /dev/null +++ b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stderr.log @@ -0,0 +1 @@ +error: the crate `cbindgen` could not be found in registry index. diff --git a/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stdout.log b/tests/testsuite/cargo_add/add_no_vendored_package_with_vendor/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 949f3a28297..bf52f6e7f51 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -1,5 +1,7 @@ mod add_basic; mod add_multiple; +mod add_no_vendored_package_with_alter_registry; +mod add_no_vendored_package_with_vendor; mod add_normalized_name_external; mod add_toolchain; mod build;