Skip to content

Commit b7a0d9b

Browse files
committed
refactor(update): Pull out latest formatting logic
1 parent 0034ea3 commit b7a0d9b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
166166
};
167167
let mut unchanged_behind = 0;
168168
for (removed, added, unchanged) in compare_dependency_graphs(&previous_resolve, &resolve) {
169+
fn format_latest(version: semver::Version) -> String {
170+
let warn = style::WARN;
171+
format!(" {warn}(latest: v{version}){warn:#}")
172+
}
173+
169174
let highest_present = [added.iter().rev().next(), unchanged.iter().rev().next()]
170175
.into_iter()
171176
.flatten()
@@ -185,7 +190,6 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
185190
std::task::Poll::Pending => registry.block_until_ready()?,
186191
}
187192
};
188-
let warn = style::WARN;
189193
let present_version = present.version();
190194
possibilities
191195
.iter()
@@ -201,7 +205,7 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
201205
.map(|s| s.version().clone())
202206
.max()
203207
.filter(|v| present.version() < v)
204-
.map(|v| format!(" {warn}(latest: v{v}){warn:#}"))
208+
.map(format_latest)
205209
} else {
206210
None
207211
}

0 commit comments

Comments
 (0)