Skip to content

Commit 3658906

Browse files
committed
Auto merge of #9665 - gilescope:giles-better-message, r=alexcrichton
Spot the crate typo easily ego tweak to make it easy to spot typos: Before: ``` error: no matching package named `sc-consensus-primitivies` found location searched: /Users/bit/p/substrate1/client/primitives/consensus/common perhaps you meant: sc-consensus-primitives required by package `sc-network v0.9.0 (/Users/bit/p/substrate1/client/network)` ``` After: ``` error: no matching package named `sc-consensus-primitivies` found perhaps you meant: sc-consensus-primitives location searched: /Users/bit/p/substrate1/client/primitives/consensus/common required by package `sc-network v0.9.0 (/Users/bit/p/substrate1/client/network)` ```
2 parents 38c8ce6 + e94199c commit 3658906

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/cargo/core/resolver/errors.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ pub(super) fn activation_error(
284284
.filter(|&(d, _)| d < 4)
285285
.collect();
286286
candidates.sort_by_key(|o| o.0);
287-
let mut msg = format!(
288-
"no matching package named `{}` found\n\
289-
location searched: {}\n",
290-
dep.package_name(),
291-
dep.source_id()
292-
);
293-
if !candidates.is_empty() {
287+
let mut msg: String;
288+
if candidates.is_empty() {
289+
msg = format!("no matching package named `{}` found\n", dep.package_name());
290+
} else {
291+
msg = format!(
292+
"no matching package found\nsearched package name: `{}`\n",
293+
dep.package_name()
294+
);
295+
294296
// If dependency package name is equal to the name of the candidate here
295297
// it may be a prerelease package which hasn't been specified correctly
296298
if dep.package_name() == candidates[0].1.name()
@@ -312,8 +314,9 @@ pub(super) fn activation_error(
312314
if candidates.len() > 3 {
313315
names.push("...");
314316
}
315-
316-
msg.push_str("perhaps you meant: ");
317+
// Vertically align first suggestion with missing crate name
318+
// so a typo jumps out at you.
319+
msg.push_str("perhaps you meant: ");
317320
msg.push_str(&names.iter().enumerate().fold(
318321
String::default(),
319322
|acc, (i, el)| match i {
@@ -323,9 +326,9 @@ pub(super) fn activation_error(
323326
},
324327
));
325328
}
326-
327329
msg.push('\n');
328330
}
331+
msg.push_str(&format!("location searched: {}\n", dep.source_id()));
329332
msg.push_str("required by ");
330333
msg.push_str(&describe_path(
331334
&cx.parents.path_to_bottom(&parent.package_id()),

tests/testsuite/directory.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ fn simple_install_fail() {
191191
error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]`
192192
193193
Caused by:
194-
no matching package named `baz` found
194+
no matching package found
195+
searched package name: `baz`
196+
perhaps you meant: bar or foo
195197
location searched: registry `https://github.com/rust-lang/crates.io-index`
196-
perhaps you meant: bar or foo
197198
required by package `bar v0.1.0`
198199
",
199200
)

tests/testsuite/path.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,10 @@ fn invalid_path_dep_in_workspace_with_lockfile() {
964964
.with_status(101)
965965
.with_stderr(
966966
"\
967-
error: no matching package named `bar` found
967+
error: no matching package found
968+
searched package name: `bar`
969+
perhaps you meant: foo
968970
location searched: [..]
969-
perhaps you meant: foo
970971
required by package `foo v0.5.0 ([..])`
971972
",
972973
)

tests/testsuite/registry.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ fn wrong_case() {
155155
.with_stderr(
156156
"\
157157
[UPDATING] [..] index
158-
error: no matching package named `Init` found
158+
error: no matching package found
159+
searched package name: `Init`
160+
perhaps you meant: init
159161
location searched: registry [..]
160-
perhaps you meant: init
161162
required by package `foo v0.0.1 ([..])`
162163
",
163164
)
@@ -190,9 +191,10 @@ fn mis_hyphenated() {
190191
.with_stderr(
191192
"\
192193
[UPDATING] [..] index
193-
error: no matching package named `mis_hyphenated` found
194+
error: no matching package found
195+
searched package name: `mis_hyphenated`
196+
perhaps you meant: mis-hyphenated
194197
location searched: registry [..]
195-
perhaps you meant: mis-hyphenated
196198
required by package `foo v0.0.1 ([..])`
197199
",
198200
)
@@ -1438,10 +1440,11 @@ fn use_semver_package_incorrectly() {
14381440
.with_status(101)
14391441
.with_stderr(
14401442
"\
1441-
error: no matching package named `a` found
1442-
location searched: [..]
1443+
error: no matching package found
1444+
searched package name: `a`
14431445
prerelease package needs to be specified explicitly
14441446
a = { version = \"0.1.1-alpha.0\" }
1447+
location searched: [..]
14451448
required by package `b v0.1.0 ([..])`
14461449
",
14471450
)

0 commit comments

Comments
 (0)