@@ -200,23 +200,21 @@ impl UnifyAnalyzer {
200200
201201 // Always use highest version (cargo's resolver already picks highest compatible)
202202 // When targets resolve to different versions, we unify to highest
203- let version = if unique_versions. len ( ) > 1 {
204- // Multiple versions found across targets - use highest
205- // This is the "silent win" - we unify duplicates automatically
206- let selected = unique_versions. iter ( ) . max ( ) . unwrap ( ) ;
207-
208- // Track the cleanup for reporting
209- let mut versions_found: Vec < _ > = unique_versions. iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ;
210- versions_found. sort ( ) ;
211- duplicates_cleaned. push ( DuplicateCleanup {
212- dep_name : dep_key. name . to_string ( ) ,
213- versions_found,
214- selected_version : selected. to_string ( ) ,
215- } ) ;
216-
217- selected
218- } else {
219- unique_versions. iter ( ) . next ( ) . unwrap ( )
203+ let version = match unique_versions. iter ( ) . max ( ) {
204+ Some ( max) if unique_versions. len ( ) > 1 => {
205+ // Multiple versions found across targets - use highest
206+ // This is the "silent win" - we unify duplicates automatically
207+ let mut versions_found: Vec < _ > = unique_versions. iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ;
208+ versions_found. sort ( ) ;
209+ duplicates_cleaned. push ( DuplicateCleanup {
210+ dep_name : dep_key. name . to_string ( ) ,
211+ versions_found,
212+ selected_version : max. to_string ( ) ,
213+ } ) ;
214+ max
215+ }
216+ Some ( version) => version,
217+ None => continue , // Empty set - shouldn't happen given versions check above
220218 } ;
221219
222220 // Construct version requirement - preserve exact pins if configured
@@ -227,9 +225,15 @@ impl UnifyAnalyzer {
227225 . find_map ( |u| u. declared_version . as_ref ( ) . filter ( |v| is_exact_pin ( v) ) )
228226 . cloned ( )
229227 . unwrap_or_else ( || format ! ( "={}" , version) ) ;
230- VersionReq :: parse ( & exact_version) . unwrap_or_else ( |_| VersionReq :: parse ( & format ! ( "^{}" , version) ) . unwrap ( ) )
228+ // Try exact version first, fall back to caret format, then ultimate fallback
229+ VersionReq :: parse ( & exact_version)
230+ . or_else ( |_| VersionReq :: parse ( & format ! ( "^{}" , version) ) )
231+ . unwrap_or_else ( |_| VersionReq :: default ( ) )
231232 } else {
232- VersionReq :: parse ( & format ! ( "^{}" , version) ) . unwrap_or_else ( |_| VersionReq :: parse ( & version. to_string ( ) ) . unwrap ( ) )
233+ // Try caret format first, fall back to plain version, then ultimate fallback
234+ VersionReq :: parse ( & format ! ( "^{}" , version) )
235+ . or_else ( |_| VersionReq :: parse ( & version. to_string ( ) ) )
236+ . unwrap_or_else ( |_| VersionReq :: default ( ) )
233237 } ;
234238
235239 // Check for version mismatches with existing workspace.dependencies
0 commit comments