@@ -424,7 +424,7 @@ fn check_ssh_known_hosts_loaded(
424
424
}
425
425
}
426
426
427
- if latent_errors. len ( ) == 0 {
427
+ if latent_errors. is_empty ( ) {
428
428
// FIXME: Ideally the error message should include the IP address of the
429
429
// remote host (to help the user validate that they are connecting to the
430
430
// 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(
440
440
// We're going to take the first HostKeyHasChanged error if
441
441
// we find one, otherwise we'll take the first error (which
442
442
// 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 ( ) )
460
452
}
461
- // Otherwise, we take the first error (which we expect to be
462
- // a CertAuthority error).
463
- Err ( latent_errors. pop ( ) . unwrap ( ) )
464
453
}
465
454
}
466
455
0 commit comments