diff --git a/src/cargo/core/resolver/version_prefs.rs b/src/cargo/core/resolver/version_prefs.rs index e84d24ba066..2d78f30862d 100644 --- a/src/cargo/core/resolver/version_prefs.rs +++ b/src/cargo/core/resolver/version_prefs.rs @@ -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); } } @@ -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![]); + } }