From 67dbfe536d8c36cd701e70a6fdc3098cb5450a13 Mon Sep 17 00:00:00 2001 From: Alik Aslanyan Date: Mon, 14 Jan 2019 23:34:46 +0400 Subject: [PATCH] Perhaps you meant: bar, foo or foobar --- src/cargo/core/resolver/errors.rs | 11 +++++++++-- tests/testsuite/directory.rs | 2 +- tests/testsuite/path.rs | 2 +- tests/testsuite/registry.rs | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index dde505d1af8..20c8d888776 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -253,8 +253,15 @@ pub(super) fn activation_error( names.push("..."); } - msg.push_str("did you mean: "); - msg.push_str(&names.join(", ")); + msg.push_str("perhaps you meant: "); + msg.push_str(&names.iter().enumerate().fold( + String::default(), + |acc, (i, el)| match i { + 0 => acc + el, + i if names.len() - 1 == i && candidates.len() <= 3 => acc + " or " + el, + _ => acc + ", " + el, + }, + )); msg.push_str("\n"); } msg.push_str("required by "); diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index c4b0f70f073..081e0be0e27 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -189,7 +189,7 @@ error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[ Caused by: no matching package named `baz` found location searched: registry `https://github.com/rust-lang/crates.io-index` -did you mean: bar, foo +perhaps you meant: bar or foo required by package `bar v0.1.0` ", ) diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 2c818c9cdf1..3b910a7fe90 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -981,7 +981,7 @@ fn invalid_path_dep_in_workspace_with_lockfile() { "\ error: no matching package named `bar` found location searched: [..] -did you mean: foo +perhaps you meant: foo required by package `foo v0.5.0 ([..])` ", ) diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 31babf88b75..efc88b72c3c 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -155,7 +155,7 @@ fn wrong_case() { [UPDATING] [..] index error: no matching package named `Init` found location searched: registry [..] -did you mean: init +perhaps you meant: init required by package `foo v0.0.1 ([..])` ", ) @@ -190,7 +190,7 @@ fn mis_hyphenated() { [UPDATING] [..] index error: no matching package named `mis_hyphenated` found location searched: registry [..] -did you mean: mis-hyphenated +perhaps you meant: mis-hyphenated required by package `foo v0.0.1 ([..])` ", )