Skip to content

Commit

Permalink
Auto merge of #13287 - weihanglo:sort-summaries, r=Eh2406
Browse files Browse the repository at this point in the history
fix(resolver): do not panic when sorting empty summaries
  • Loading branch information
bors committed Jan 12, 2024
2 parents bf27f90 + 6cee9bf commit 84976cd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cargo/core/resolver/version_prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl VersionPreferences {
VersionOrdering::MinimumVersionsFirst => cmp,
}
});
if first_version.is_some() {
if first_version.is_some() && !summaries.is_empty() {
let _ = summaries.split_off(1);
}
}
Expand Down Expand Up @@ -283,4 +283,13 @@ mod test {
.to_string()
);
}

#[test]
fn test_empty_summaries() {
let vp = VersionPreferences::default();
let mut summaries = vec![];

vp.sort_summaries(&mut summaries, Some(VersionOrdering::MaximumVersionsFirst));
assert_eq!(summaries, vec![]);
}
}

0 comments on commit 84976cd

Please sign in to comment.