Skip to content

Commit 2115265

Browse files
committed
Move check to the end of function, rework error message
1 parent 8c4b0a8 commit 2115265

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

src/cargo/core/workspace.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,22 +1250,6 @@ impl<'cfg> Workspace<'cfg> {
12501250
uses_default_features: cli_features.uses_default_features,
12511251
};
12521252

1253-
// If any member specific features were passed to non-virtual package, it's error
1254-
if !member_specific_features.is_empty() {
1255-
let invalid: Vec<_> = member_specific_features
1256-
.values()
1257-
.map(|set| set.iter())
1258-
.flatten()
1259-
.map(|feature| feature.to_string())
1260-
.sorted()
1261-
.collect();
1262-
1263-
bail!(
1264-
"Member specific features with `pkg/feat` syntax are dissalowed outside of workspace with `resolver = \"1\", remove: {}",
1265-
invalid.join(", ")
1266-
);
1267-
}
1268-
12691253
result.push((member, feats))
12701254
}
12711255
_ => {
@@ -1312,6 +1296,42 @@ impl<'cfg> Workspace<'cfg> {
13121296
}
13131297
}
13141298

1299+
// If any member specific features were not removed while iterating over members
1300+
if !member_specific_features.is_empty() {
1301+
let unknown: Vec<_> = member_specific_features
1302+
.values()
1303+
.map(|set| set.iter())
1304+
.flatten()
1305+
.sorted_by_key(|feature| feature.to_string())
1306+
.collect();
1307+
1308+
if self.is_virtual() {
1309+
bail!(
1310+
"None of the selected packages contains these features: {}",
1311+
unknown.iter().join(", "),
1312+
);
1313+
} else {
1314+
bail!(
1315+
"None of the selected packages contains these features: {}, did you mean: {}?",
1316+
unknown.iter().join(", "),
1317+
unknown
1318+
.iter()
1319+
.map(|feature| match feature {
1320+
// Remove package prefix from feature
1321+
FeatureValue::DepFeature {
1322+
dep_name: _,
1323+
dep_feature,
1324+
dep_prefix: false,
1325+
weak: _,
1326+
} => FeatureValue::new(*dep_feature),
1327+
// Member specific features by definition contain only `FeatureValue::DepFeature`
1328+
_ => unreachable!(),
1329+
})
1330+
.join(", ")
1331+
);
1332+
}
1333+
}
1334+
13151335
Ok(result)
13161336
}
13171337
}

tests/testsuite/package_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn feature_default_resolver() {
313313
p.cargo("run --features a/test")
314314
.masquerade_as_nightly_cargo()
315315
.with_status(101)
316-
.with_stderr("[ERROR] Member specific features with `pkg/feat` syntax are dissalowed outside of workspace with `resolver = \"1\", remove: a/test")
316+
.with_stderr("[ERROR] None of the selected packages contains these features: a/test, did you mean: test?")
317317
.run();
318318
}
319319

0 commit comments

Comments
 (0)