From 8bb5ce6e37fca163ff9ff2374d8c87e93916477a Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 25 Mar 2024 23:03:46 -0400 Subject: [PATCH] fix: do not borrow shell across registry query --- src/cargo/ops/cargo_generate_lockfile.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index cb7a2a8114ce..47876ee9eff0 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -184,15 +184,14 @@ fn print_lockfile_generation( resolve: &Resolve, registry: &mut PackageRegistry<'_>, ) -> CargoResult<()> { - let mut shell = gctx.shell(); - let diff = PackageDiff::new(&resolve); let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum(); if num_pkgs <= 1 { // just ourself, nothing worth reporting return Ok(()); } - shell.status("Locking", format!("{num_pkgs} packages"))?; + gctx.shell() + .status("Locking", format!("{num_pkgs} packages"))?; for diff in diff { fn format_latest(version: semver::Version) -> String { @@ -212,6 +211,8 @@ fn print_lockfile_generation( vec![] }; + let mut shell = gctx.shell(); + for package in diff.added.iter() { let latest = if !possibilities.is_empty() { possibilities @@ -240,15 +241,14 @@ fn print_lockfile_sync( resolve: &Resolve, registry: &mut PackageRegistry<'_>, ) -> CargoResult<()> { - let mut shell = gctx.shell(); - let diff = PackageDiff::diff(&previous_resolve, &resolve); let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum(); if num_pkgs == 0 { return Ok(()); } let plural = if num_pkgs == 1 { "" } else { "s" }; - shell.status("Locking", format!("{num_pkgs} package{plural}"))?; + gctx.shell() + .status("Locking", format!("{num_pkgs} package{plural}"))?; for diff in diff { fn format_latest(version: semver::Version) -> String { @@ -268,6 +268,7 @@ fn print_lockfile_sync( vec![] }; + let mut shell = gctx.shell(); if let Some((removed, added)) = diff.change() { let latest = if !possibilities.is_empty() { possibilities @@ -329,8 +330,6 @@ pub fn print_lockfile_updates( resolve: &Resolve, registry: &mut PackageRegistry<'_>, ) -> CargoResult<()> { - let mut shell = gctx.shell(); - let mut unchanged_behind = 0; for diff in PackageDiff::diff(&previous_resolve, &resolve) { fn format_latest(version: semver::Version) -> String { @@ -350,6 +349,7 @@ pub fn print_lockfile_updates( vec![] }; + let mut shell = gctx.shell(); if let Some((removed, added)) = diff.change() { let latest = if !possibilities.is_empty() { possibilities @@ -428,6 +428,8 @@ pub fn print_lockfile_updates( } } } + + let mut shell = gctx.shell(); if shell.verbosity() == Verbosity::Verbose { shell.note( "to see how you depend on a package, run `cargo tree --invert --package @`",