Add error message for wrong cargo-features placement.

This is intended to help if the user puts cargo-features in the
wrong place in Cargo.toml.
This commit is contained in:
Eric Huss 2021-01-20 19:22:51 -08:00
parent 73b98edc34
commit d89a78ee19
2 changed files with 40 additions and 0 deletions

View File

@ -69,6 +69,17 @@ fn do_read_manifest(
parse(contents, pretty_filename, config)? parse(contents, pretty_filename, config)?
}; };
// Provide a helpful error message for a common user error.
if let Some(package) = toml.get("package").or_else(|| toml.get("project")) {
if let Some(feats) = package.get("cargo-features") {
bail!(
"cargo-features = {} was found in the wrong location, it \
should be set at the top of Cargo.toml before any tables",
toml::to_string(feats).unwrap()
);
}
}
let mut unused = BTreeSet::new(); let mut unused = BTreeSet::new();
let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| { let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| {
let mut key = String::new(); let mut key = String::new();

View File

@ -327,3 +327,32 @@ fn publish_allowed() {
.masquerade_as_nightly_cargo() .masquerade_as_nightly_cargo()
.run(); .run();
} }
#[cargo_test]
fn wrong_position() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
cargo-features = ["test-dummy-unstable"]
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at [..]
Caused by:
cargo-features = [\"test-dummy-unstable\"] was found in the wrong location, it \
should be set at the top of Cargo.toml before any tables
",
)
.run();
}