mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
More helpful error for invalid cargo-features = []
This commit is contained in:
parent
5fff1e0e76
commit
45b4faa04a
@ -620,7 +620,32 @@ impl Features {
|
||||
) -> CargoResult<()> {
|
||||
let nightly_features_allowed = self.nightly_features_allowed;
|
||||
let Some((slot, feature)) = self.status(feature_name) else {
|
||||
bail!("unknown cargo feature `{}`", feature_name)
|
||||
let mut msg = format!("unknown Cargo.toml feature `{feature_name}`\n\n");
|
||||
let mut append_see_docs = true;
|
||||
|
||||
if feature_name.contains('_') {
|
||||
let _ = writeln!(msg, "Feature names must use '-' instead of '_'.");
|
||||
append_see_docs = false;
|
||||
} else {
|
||||
let underscore_name = feature_name.replace('-', "_");
|
||||
if CliUnstable::help()
|
||||
.iter()
|
||||
.any(|(option, _)| *option == underscore_name)
|
||||
{
|
||||
let _ = writeln!(
|
||||
msg,
|
||||
"This feature can be enabled via -Z{feature_name} or the `[unstable]` section in config.toml."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if append_see_docs {
|
||||
let _ = writeln!(
|
||||
msg,
|
||||
"See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information."
|
||||
);
|
||||
}
|
||||
bail!(msg)
|
||||
};
|
||||
|
||||
if *slot {
|
||||
|
@ -173,7 +173,9 @@ fn unknown_feature() {
|
||||
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
unknown cargo feature `foo`
|
||||
unknown Cargo.toml feature `foo`
|
||||
|
||||
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information.
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
@ -202,7 +204,10 @@ fn wrong_kind_of_feature() {
|
||||
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
unknown cargo feature `build-dir`
|
||||
unknown Cargo.toml feature `build-dir`
|
||||
|
||||
This feature can be enabled via -Zbuild-dir or the `[unstable]` section in config.toml.
|
||||
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information.
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
@ -231,7 +236,9 @@ fn feature_syntax() {
|
||||
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
unknown cargo feature `bad_feature`
|
||||
unknown Cargo.toml feature `bad_feature`
|
||||
|
||||
Feature names must use '-' instead of '_'.
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user