Skip to content

Commit 93c734b

Browse files
committed
fix(features): When feature activates a typo, suggest alt
1 parent a38d44c commit 93c734b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/cargo/core/summary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::core::{Dependency, PackageId, SourceId};
2+
use crate::util::closest_msg;
23
use crate::util::interning::InternedString;
34
use crate::util::CargoResult;
45
use anyhow::bail;
@@ -241,9 +242,10 @@ fn build_feature_map(
241242
Feature(f) => {
242243
if !features.contains_key(f) {
243244
if !is_any_dep {
245+
let closest = closest_msg(f, features.keys(), |k| k, "feature");
244246
bail!(
245247
"feature `{feature}` includes `{fv}` which is neither a dependency \
246-
nor another feature"
248+
nor another feature{closest}"
247249
);
248250
}
249251
if is_optional_dep {

tests/testsuite/features.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ fn feature_activates_missing_feature() {
3232
Caused by:
3333
feature `bar` includes `baz` which is neither a dependency nor another feature
3434
35+
[HELP] a feature with a similar name exists: `bar`
36+
3537
"#]])
3638
.run();
3739
}
@@ -64,6 +66,8 @@ fn feature_activates_typoed_feature() {
6466
Caused by:
6567
feature `bar` includes `baz` which is neither a dependency nor another feature
6668
69+
[HELP] a feature with a similar name exists: `bar`
70+
6771
"#]])
6872
.run();
6973
}

tests/testsuite/features_namespaced.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ fn namespaced_invalid_feature() {
7575
Caused by:
7676
feature `bar` includes `baz` which is neither a dependency nor another feature
7777
78+
[HELP] a feature with a similar name exists: `bar`
79+
7880
"#]])
7981
.run();
8082
}

0 commit comments

Comments
 (0)