From 6cee9bf72f78385991c764bc6218fe95664eede5 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 12 Jan 2024 00:34:33 -0500 Subject: [PATCH] fix(resolver): do not panic when sorting empty summaries --- src/cargo/core/resolver/version_prefs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/resolver/version_prefs.rs b/src/cargo/core/resolver/version_prefs.rs index 963088c24e5..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); } } @@ -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![]); } }