From e94199cb0619d604981f10570845e774b449c2e5 Mon Sep 17 00:00:00 2001 From: gilescope Date: Sun, 11 Jul 2021 19:06:20 +0100 Subject: [PATCH] Only put it on a new line if there's candidates to compare against. --- src/cargo/core/resolver/errors.rs | 12 +++++++++--- tests/testsuite/registry.rs | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 0852608d197..72b190ee05b 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -284,9 +284,15 @@ pub(super) fn activation_error( .filter(|&(d, _)| d < 4) .collect(); candidates.sort_by_key(|o| o.0); - let mut msg = format!( - "no matching package found\nsearched package name: `{}`\n", dep.package_name()); - if !candidates.is_empty() { + let mut msg: String; + if candidates.is_empty() { + msg = format!("no matching package named `{}` found\n", dep.package_name()); + } else { + msg = format!( + "no matching package found\nsearched package name: `{}`\n", + dep.package_name() + ); + // If dependency package name is equal to the name of the candidate here // it may be a prerelease package which hasn't been specified correctly if dep.package_name() == candidates[0].1.name() diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index a91f8417a45..eb7b97d8632 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -1440,7 +1440,8 @@ fn use_semver_package_incorrectly() { .with_status(101) .with_stderr( "\ -error: no matching package named `a` found +error: no matching package found +searched package name: `a` prerelease package needs to be specified explicitly a = { version = \"0.1.1-alpha.0\" } location searched: [..]