diff --git a/src/cargo/ops/cargo_update.rs b/src/cargo/ops/cargo_update.rs index 879b4203571..d4737f11fa8 100644 --- a/src/cargo/ops/cargo_update.rs +++ b/src/cargo/ops/cargo_update.rs @@ -774,7 +774,7 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti let version_req = package_id.version().to_caret_req(); let required_rust_version = change.required_rust_version.as_ref(); - if let Some(summary) = possibilities + let compat_ver_compat_msrv_summary = possibilities .iter() .map(|s| s.as_summary()) .filter(|s| { @@ -787,15 +787,15 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti } }) .filter(|s| package_id.version() != s.version() && version_req.matches(s.version())) - .max_by_key(|s| s.version()) - { + .max_by_key(|s| s.version()); + if let Some(summary) = compat_ver_compat_msrv_summary { let warn = style::WARN; let version = summary.version(); let report = format!(" {warn}(available: v{version}){warn:#}"); return Some(report); } - if let Some(summary) = possibilities + let incompat_ver_compat_msrv_summary = possibilities .iter() .map(|s| s.as_summary()) .filter(|s| { @@ -808,8 +808,8 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti } }) .filter(|s| is_latest(s.version(), package_id.version())) - .max_by_key(|s| s.version()) - { + .max_by_key(|s| s.version()); + if let Some(summary) = incompat_ver_compat_msrv_summary { let warn = if change.is_transitive.unwrap_or(true) { Default::default() } else { @@ -820,12 +820,12 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti return Some(report); } - if let Some(summary) = possibilities + let compat_ver_summary = possibilities .iter() .map(|s| s.as_summary()) .filter(|s| package_id.version() != s.version() && version_req.matches(s.version())) - .max_by_key(|s| s.version()) - { + .max_by_key(|s| s.version()); + if let Some(summary) = compat_ver_summary { let msrv_note = summary .rust_version() .map(|rv| format!(", requires Rust {rv}")) @@ -836,12 +836,12 @@ fn report_latest(possibilities: &[IndexSummary], change: &PackageChange) -> Opti return Some(report); } - if let Some(summary) = possibilities + let incompat_ver_summary = possibilities .iter() .map(|s| s.as_summary()) .filter(|s| is_latest(s.version(), package_id.version())) - .max_by_key(|s| s.version()) - { + .max_by_key(|s| s.version()); + if let Some(summary) = incompat_ver_summary { let msrv_note = summary .rust_version() .map(|rv| format!(", requires Rust {rv}"))