Skip to content

Commit

Permalink
feat(update): Report when incompatible-rust-version packages are sele…
Browse files Browse the repository at this point in the history
…cted

In discussin this in rust-lang#13873, it highlighted that we need to make sure we
tell people when we get in this state.

I decided to keep "latest" and "required rust version" messages mutually
exclusive to avoid too much noise.  I gave "required rust version"
higher precedence as its the more critical to operation and, if you are
using an MSRV-incompatible package, it likely is "latest" already.

I was tempted to change colors to make "required rust version" stand out
from "latest" but was unsure what direction to go, so I held off.
Options included
- red for "required rust version", yellow for "latest"
- yellow for "required rust version", nothing for "latest"

There is also more discussion on how to format "latest" at rust-lang#13908.
  • Loading branch information
epage committed Aug 14, 2024
1 parent 374701e commit 5714116
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,14 @@ fn print_lockfile_generation(
};

for package in diff.added.iter() {
let required_rust_version = report_required_rust_version(ws, resolve, *package);
let latest = report_latest(&possibilities, *package);
let note = required_rust_version.or(latest);

if let Some(latest) = latest {
if let Some(note) = note {
ws.gctx().shell().status_with_color(
"Adding",
format!("{package}{latest}"),
format!("{package}{note}"),
&style::NOTE,
)?;
}
Expand Down Expand Up @@ -594,11 +596,13 @@ fn print_lockfile_sync(
}
} else {
for package in diff.added.iter() {
let latest = report_latest(&possibilities, *package).unwrap_or_default();
let required_rust_version = report_required_rust_version(ws, resolve, *package);
let latest = report_latest(&possibilities, *package);
let note = required_rust_version.or(latest).unwrap_or_default();

ws.gctx().shell().status_with_color(
"Adding",
format!("{package}{latest}"),
format!("{package}{note}"),
&style::NOTE,
)?;
}
Expand Down Expand Up @@ -637,15 +641,17 @@ fn print_lockfile_updates(
};

if let Some((removed, added)) = diff.change() {
let latest = report_latest(&possibilities, *added).unwrap_or_default();
let required_rust_version = report_required_rust_version(ws, resolve, *added);
let latest = report_latest(&possibilities, *added);
let note = required_rust_version.or(latest).unwrap_or_default();

let msg = if removed.source_id().is_git() {
format!(
"{removed} -> #{}",
"{removed} -> #{}{note}",
&added.source_id().precise_git_fragment().unwrap()[..8],
)
} else {
format!("{removed} -> v{}{latest}", added.version())
format!("{removed} -> v{}{note}", added.version())
};

// If versions differ only in build metadata, we call it an "update"
Expand All @@ -670,24 +676,30 @@ fn print_lockfile_updates(
)?;
}
for package in diff.added.iter() {
let latest = report_latest(&possibilities, *package).unwrap_or_default();
let required_rust_version = report_required_rust_version(ws, resolve, *package);
let latest = report_latest(&possibilities, *package);
let note = required_rust_version.or(latest).unwrap_or_default();

ws.gctx().shell().status_with_color(
"Adding",
format!("{package}{latest}"),
format!("{package}{note}"),
&style::NOTE,
)?;
}
}
for package in &diff.unchanged {
let required_rust_version = report_required_rust_version(ws, resolve, *package);
let latest = report_latest(&possibilities, *package);
let note = required_rust_version.as_deref().or(latest.as_deref());

if let Some(latest) = latest {
unchanged_behind += 1;
if let Some(note) = note {
if latest.is_some() {
unchanged_behind += 1;
}
if ws.gctx().shell().verbosity() == Verbosity::Verbose {
ws.gctx().shell().status_with_color(
"Unchanged",
format!("{package}{latest}"),
format!("{package}{note}"),
&anstyle::Style::new().bold(),
)?;
}
Expand Down Expand Up @@ -751,6 +763,24 @@ fn required_rust_version(ws: &Workspace<'_>) -> Option<PartialVersion> {
}
}

fn report_required_rust_version(
ws: &Workspace<'_>,
resolve: &Resolve,
package: PackageId,
) -> Option<String> {
let summary = resolve.summary(package);
let package_rust_version = summary.rust_version()?;
let workspace_rust_version = required_rust_version(ws)?;
if package_rust_version.is_compatible_with(&workspace_rust_version) {
return None;
}

let warn = style::WARN;
Some(format!(
" {warn}(requires Rust {package_rust_version}){warn:#}"
))
}

fn report_latest(possibilities: &[IndexSummary], package: PackageId) -> Option<String> {
if possibilities.is_empty() {
return None;
Expand Down

0 comments on commit 5714116

Please sign in to comment.