Skip to content

Commit

Permalink
Auto merge of #11541 - ehuss:fix-dep-unwrap, r=epage
Browse files Browse the repository at this point in the history
Fix panic on target dependency errors.

Errors while processing a target dependency would cause a panic due to some calls to `unwrap` in the TOML processing code. Those unwraps should not be there, and it should just propagate the errors upwards just  like is done for normal dependencies.

Fixes #11540
  • Loading branch information
bors committed Jan 5, 2023
2 parents c446c20 + fab1358 commit 247b22f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,8 +1861,7 @@ impl TomlManifest {
None,
&workspace_config,
&inherit_cell,
)
.unwrap();
)?;
if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() {
warn_on_deprecated("build-dependencies", name, "platform target", cx.warnings);
}
Expand All @@ -1876,8 +1875,7 @@ impl TomlManifest {
Some(DepKind::Build),
&workspace_config,
&inherit_cell,
)
.unwrap();
)?;
if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() {
warn_on_deprecated("dev-dependencies", name, "platform target", cx.warnings);
}
Expand All @@ -1891,8 +1889,7 @@ impl TomlManifest {
Some(DepKind::Development),
&workspace_config,
&inherit_cell,
)
.unwrap();
)?;
target.insert(
name.clone(),
TomlPlatform {
Expand Down
28 changes: 22 additions & 6 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,16 +1141,32 @@ fn ignored_git_revision() {
.file("src/lib.rs", "")
.build();

foo.cargo("build -v")
.with_status(101)
.with_stderr(
"\
let err_msg = "\
error: failed to parse manifest at `[..]`
Caused by:
key `branch` is ignored for dependency (bar).
",
)
";
foo.cargo("build -v")
.with_status(101)
.with_stderr(err_msg)
.run();

// #11540, check that [target] dependencies fail the same way.
foo.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.0"
[target.some-target.dependencies]
bar = { path = "bar", branch = "spam" }
"#,
);
foo.cargo("build")
.with_status(101)
.with_stderr(err_msg)
.run();
}

Expand Down

0 comments on commit 247b22f

Please sign in to comment.