Skip to content

Commit 4043114

Browse files
committed
More helpful error for invalid cargo-features = []
1 parent 63b863b commit 4043114

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/cargo/core/features.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,28 @@ impl Features {
620620
) -> CargoResult<()> {
621621
let nightly_features_allowed = self.nightly_features_allowed;
622622
let Some((slot, feature)) = self.status(feature_name) else {
623-
bail!("unknown cargo feature `{}`", feature_name)
623+
let mut msg = format!("unknown Cargo.toml feature `{feature_name}`\n\n");
624+
625+
if feature_name.contains('_') {
626+
let _ = writeln!(msg, "Feature names must use '-' instead of '_'.");
627+
} else {
628+
let underscore_name = feature_name.replace('-', "_");
629+
if CliUnstable::help()
630+
.iter()
631+
.any(|(option, _)| *option == underscore_name)
632+
{
633+
let _ = writeln!(
634+
msg,
635+
"This feature can be enabled via -Z{feature_name} or the `[unstable]` section in config.toml."
636+
);
637+
}
638+
}
639+
640+
let _ = writeln!(
641+
msg,
642+
"See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information."
643+
);
644+
bail!(msg)
624645
};
625646

626647
if *slot {

0 commit comments

Comments
 (0)