Skip to content

Commit d89a78e

Browse files
committed
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.
1 parent 73b98ed commit d89a78e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ fn do_read_manifest(
6969
parse(contents, pretty_filename, config)?
7070
};
7171

72+
// Provide a helpful error message for a common user error.
73+
if let Some(package) = toml.get("package").or_else(|| toml.get("project")) {
74+
if let Some(feats) = package.get("cargo-features") {
75+
bail!(
76+
"cargo-features = {} was found in the wrong location, it \
77+
should be set at the top of Cargo.toml before any tables",
78+
toml::to_string(feats).unwrap()
79+
);
80+
}
81+
}
82+
7283
let mut unused = BTreeSet::new();
7384
let manifest: TomlManifest = serde_ignored::deserialize(toml, |path| {
7485
let mut key = String::new();

tests/testsuite/cargo_features.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,32 @@ fn publish_allowed() {
327327
.masquerade_as_nightly_cargo()
328328
.run();
329329
}
330+
331+
#[cargo_test]
332+
fn wrong_position() {
333+
let p = project()
334+
.file(
335+
"Cargo.toml",
336+
r#"
337+
[package]
338+
name = "foo"
339+
version = "0.1.0"
340+
cargo-features = ["test-dummy-unstable"]
341+
"#,
342+
)
343+
.file("src/lib.rs", "")
344+
.build();
345+
p.cargo("check")
346+
.masquerade_as_nightly_cargo()
347+
.with_status(101)
348+
.with_stderr(
349+
"\
350+
error: failed to parse manifest at [..]
351+
352+
Caused by:
353+
cargo-features = [\"test-dummy-unstable\"] was found in the wrong location, it \
354+
should be set at the top of Cargo.toml before any tables
355+
",
356+
)
357+
.run();
358+
}

0 commit comments

Comments
 (0)