Skip to content

Commit

Permalink
Auto merge of #6550 - In-line:did-you-mean-with-question-mark, r=dwij…
Browse files Browse the repository at this point in the history
…nand

Perhaps you meant: foo, bar or foobar

Hi! Rust project is very cool, but I noticed some minor issues. In every place `did you mean: bla bla` end with the question mark, so I decided to include it here too.
  • Loading branch information
bors committed Jan 20, 2019
2 parents 2a15e57 + 67dbfe5 commit 6d5cd59
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([..])`
",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([..])`
",
)
Expand Down Expand Up @@ -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 ([..])`
",
)
Expand Down

0 comments on commit 6d5cd59

Please sign in to comment.