Fix panic with -Zbuild-std and no roots.

This commit is contained in:
Eric Huss 2020-12-04 13:34:09 -08:00
parent 5c40b7f6dc
commit 6b472c90e1
2 changed files with 26 additions and 0 deletions

View File

@ -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),

View File

@ -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();
}