Skip to content

Commit 90b10cd

Browse files
committed
refactor(update): Simplify Upgrade/Downgrade display logic
1 parent de15651 commit 90b10cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,22 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
212212
.unwrap_or_default();
213213

214214
if removed.len() == 1 && added.len() == 1 {
215-
let msg = if removed[0].source_id().is_git() {
215+
let added = added.into_iter().next().unwrap();
216+
let removed = removed.into_iter().next().unwrap();
217+
let msg = if removed.source_id().is_git() {
216218
format!(
217-
"{} -> #{}",
218-
removed[0],
219-
&added[0].source_id().precise_git_fragment().unwrap()[..8],
219+
"{removed} -> #{}",
220+
&added.source_id().precise_git_fragment().unwrap()[..8],
220221
)
221222
} else {
222-
format!("{} -> v{}{latest}", removed[0], added[0].version())
223+
format!("{removed} -> v{}{latest}", added.version())
223224
};
224225

225226
// If versions differ only in build metadata, we call it an "update"
226227
// regardless of whether the build metadata has gone up or down.
227228
// This metadata is often stuff like git commit hashes, which are
228229
// not meaningfully ordered.
229-
if removed[0].version().cmp_precedence(added[0].version()) == Ordering::Greater {
230+
if removed.version().cmp_precedence(added.version()) == Ordering::Greater {
230231
print_change("Downgrading", msg, &style::WARN)?;
231232
} else {
232233
print_change("Updating", msg, &style::GOOD)?;

0 commit comments

Comments
 (0)