Skip to content

Commit a871a90

Browse files
hdsehuss
andauthored
Apply suggestions from code review
Co-authored-by: Eric Huss <eric@huss.org>
1 parent 605506a commit a871a90

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/cargo/sources/git/known_hosts.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn check_ssh_known_hosts_loaded(
424424
}
425425
}
426426

427-
if latent_errors.len() == 0 {
427+
if latent_errors.is_empty() {
428428
// FIXME: Ideally the error message should include the IP address of the
429429
// remote host (to help the user validate that they are connecting to the
430430
// host they were expecting to). However, I don't see a way to obtain that
@@ -440,27 +440,16 @@ fn check_ssh_known_hosts_loaded(
440440
// We're going to take the first HostKeyHasChanged error if
441441
// we find one, otherwise we'll take the first error (which
442442
// we expect to be a CertAuthority error).
443-
for err in &latent_errors {
444-
if let KnownHostError::HostKeyHasChanged {
445-
hostname,
446-
key_type,
447-
old_known_host,
448-
remote_host_key,
449-
remote_fingerprint,
450-
} = err
451-
{
452-
return Err(KnownHostError::HostKeyHasChanged {
453-
hostname: hostname.clone(),
454-
key_type: key_type.clone(),
455-
old_known_host: old_known_host.clone(),
456-
remote_host_key: remote_host_key.clone(),
457-
remote_fingerprint: remote_fingerprint.clone(),
458-
});
459-
}
443+
if let Some(index) = latent_errors
444+
.iter()
445+
.position(|e| matches!(e, KnownHostError::HostKeyHasChanged { .. }))
446+
{
447+
return Err(latent_errors.remove(index));
448+
} else {
449+
// Otherwise, we take the first error (which we expect to be
450+
// a CertAuthority error).
451+
Err(latent_errors.pop().unwrap())
460452
}
461-
// Otherwise, we take the first error (which we expect to be
462-
// a CertAuthority error).
463-
Err(latent_errors.pop().unwrap())
464453
}
465454
}
466455

0 commit comments

Comments
 (0)