Skip to content

Commit 247b22f

Browse files
committed
Auto merge of #11541 - ehuss:fix-dep-unwrap, r=epage
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
2 parents c446c20 + fab1358 commit 247b22f

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,8 +1861,7 @@ impl TomlManifest {
18611861
None,
18621862
&workspace_config,
18631863
&inherit_cell,
1864-
)
1865-
.unwrap();
1864+
)?;
18661865
if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() {
18671866
warn_on_deprecated("build-dependencies", name, "platform target", cx.warnings);
18681867
}
@@ -1876,8 +1875,7 @@ impl TomlManifest {
18761875
Some(DepKind::Build),
18771876
&workspace_config,
18781877
&inherit_cell,
1879-
)
1880-
.unwrap();
1878+
)?;
18811879
if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() {
18821880
warn_on_deprecated("dev-dependencies", name, "platform target", cx.warnings);
18831881
}
@@ -1891,8 +1889,7 @@ impl TomlManifest {
18911889
Some(DepKind::Development),
18921890
&workspace_config,
18931891
&inherit_cell,
1894-
)
1895-
.unwrap();
1892+
)?;
18961893
target.insert(
18971894
name.clone(),
18981895
TomlPlatform {

tests/testsuite/bad_config.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,16 +1141,32 @@ fn ignored_git_revision() {
11411141
.file("src/lib.rs", "")
11421142
.build();
11431143

1144-
foo.cargo("build -v")
1145-
.with_status(101)
1146-
.with_stderr(
1147-
"\
1144+
let err_msg = "\
11481145
error: failed to parse manifest at `[..]`
11491146
11501147
Caused by:
11511148
key `branch` is ignored for dependency (bar).
1152-
",
1153-
)
1149+
";
1150+
foo.cargo("build -v")
1151+
.with_status(101)
1152+
.with_stderr(err_msg)
1153+
.run();
1154+
1155+
// #11540, check that [target] dependencies fail the same way.
1156+
foo.change_file(
1157+
"Cargo.toml",
1158+
r#"
1159+
[package]
1160+
name = "foo"
1161+
version = "0.0.0"
1162+
1163+
[target.some-target.dependencies]
1164+
bar = { path = "bar", branch = "spam" }
1165+
"#,
1166+
);
1167+
foo.cargo("build")
1168+
.with_status(101)
1169+
.with_stderr(err_msg)
11541170
.run();
11551171
}
11561172

0 commit comments

Comments
 (0)