Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perhaps you meant: foo, bar or foobar #6550

Merged
merged 1 commit into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor Author

@In-line In-line Jan 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code idiomatic way to achieve what we want?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but it looks like how I'd do it :)

},
));
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