Skip to content

Commit

Permalink
Fix panic with -Zbuild-std and no roots.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Dec 4, 2020
1 parent 5c40b7f commit 6b472c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub fn build_unit_dependencies<'a, 'cfg>(
profiles: &'a Profiles,
interner: &'a UnitInterner,
) -> CargoResult<UnitGraph> {
if roots.is_empty() {
// If -Zbuild-std, don't attach units if there is nothing to build.
// Otherwise, other parts of the code may be confused by seeing units
// in the dep graph without a root.
return Ok(HashMap::new());
}
let (std_resolve, std_features) = match std_resolve {
Some((r, f)) => (Some(r), Some(f)),
None => (None, None),
Expand Down
20 changes: 20 additions & 0 deletions tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,3 +677,23 @@ fn different_features() {
.target_host()
.run();
}

#[cargo_test]
fn no_roots() {
// Checks for a bug where it would panic if there are no roots.
let setup = match setup() {
Some(s) => s,
None => return,
};
let p = project().file("tests/t1.rs", "").build();
p.cargo("build")
.build_std(&setup)
.target_host()
.with_stderr(
"\
[UPDATING] [..]
[FINISHED] [..]
",
)
.run();
}

0 comments on commit 6b472c9

Please sign in to comment.