Skip to content

Commit

Permalink
Only put it on a new line if there's candidates to compare against.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope committed Jul 14, 2021
1 parent dc0e53b commit e94199c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: [..]
Expand Down

0 comments on commit e94199c

Please sign in to comment.