Skip to content

Commit 6d5cd59

Browse files
committed
Auto merge of #6550 - In-line:did-you-mean-with-question-mark, r=dwijnand
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.
2 parents 2a15e57 + 67dbfe5 commit 6d5cd59

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/cargo/core/resolver/errors.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,15 @@ pub(super) fn activation_error(
253253
names.push("...");
254254
}
255255

256-
msg.push_str("did you mean: ");
257-
msg.push_str(&names.join(", "));
256+
msg.push_str("perhaps you meant: ");
257+
msg.push_str(&names.iter().enumerate().fold(
258+
String::default(),
259+
|acc, (i, el)| match i {
260+
0 => acc + el,
261+
i if names.len() - 1 == i && candidates.len() <= 3 => acc + " or " + el,
262+
_ => acc + ", " + el,
263+
},
264+
));
258265
msg.push_str("\n");
259266
}
260267
msg.push_str("required by ");

tests/testsuite/directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[
189189
Caused by:
190190
no matching package named `baz` found
191191
location searched: registry `https://github.com/rust-lang/crates.io-index`
192-
did you mean: bar, foo
192+
perhaps you meant: bar or foo
193193
required by package `bar v0.1.0`
194194
",
195195
)

tests/testsuite/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ fn invalid_path_dep_in_workspace_with_lockfile() {
981981
"\
982982
error: no matching package named `bar` found
983983
location searched: [..]
984-
did you mean: foo
984+
perhaps you meant: foo
985985
required by package `foo v0.5.0 ([..])`
986986
",
987987
)

tests/testsuite/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn wrong_case() {
155155
[UPDATING] [..] index
156156
error: no matching package named `Init` found
157157
location searched: registry [..]
158-
did you mean: init
158+
perhaps you meant: init
159159
required by package `foo v0.0.1 ([..])`
160160
",
161161
)
@@ -190,7 +190,7 @@ fn mis_hyphenated() {
190190
[UPDATING] [..] index
191191
error: no matching package named `mis_hyphenated` found
192192
location searched: registry [..]
193-
did you mean: mis-hyphenated
193+
perhaps you meant: mis-hyphenated
194194
required by package `foo v0.0.1 ([..])`
195195
",
196196
)

0 commit comments

Comments
 (0)