Skip to content

Commit

Permalink
fix(resolver): do not panic when sorting empty summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jan 12, 2024
1 parent c677f73 commit 6cee9bf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 @@ -284,12 +284,12 @@ mod test {
);
}

#[should_panic = "`at` split index (is 1) should be <= len (is 0)"]
#[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 6cee9bf

Please sign in to comment.