@@ -434,7 +434,7 @@ fn check_ssh_known_hosts_loaded(
434
434
return Ok ( ( ) ) ;
435
435
}
436
436
437
- if latent_errors. len ( ) == 0 {
437
+ if latent_errors. is_empty ( ) {
438
438
// FIXME: Ideally the error message should include the IP address of the
439
439
// remote host (to help the user validate that they are connecting to the
440
440
// host they were expecting to). However, I don't see a way to obtain that
@@ -450,27 +450,16 @@ fn check_ssh_known_hosts_loaded(
450
450
// We're going to take the first HostKeyHasChanged error if
451
451
// we find one, otherwise we'll take the first error (which
452
452
// we expect to be a CertAuthority error).
453
- for err in & latent_errors {
454
- if let KnownHostError :: HostKeyHasChanged {
455
- hostname,
456
- key_type,
457
- old_known_host,
458
- remote_host_key,
459
- remote_fingerprint,
460
- } = err
461
- {
462
- return Err ( KnownHostError :: HostKeyHasChanged {
463
- hostname : hostname. clone ( ) ,
464
- key_type : key_type. clone ( ) ,
465
- old_known_host : old_known_host. clone ( ) ,
466
- remote_host_key : remote_host_key. clone ( ) ,
467
- remote_fingerprint : remote_fingerprint. clone ( ) ,
468
- } ) ;
469
- }
453
+ if let Some ( index) = latent_errors
454
+ . iter ( )
455
+ . position ( |e| matches ! ( e, KnownHostError :: HostKeyHasChanged { .. } ) )
456
+ {
457
+ return Err ( latent_errors. remove ( index) ) ;
458
+ } else {
459
+ // Otherwise, we take the first error (which we expect to be
460
+ // a CertAuthority error).
461
+ Err ( latent_errors. pop ( ) . unwrap ( ) )
470
462
}
471
- // Otherwise, we take the first error (which we expect to be
472
- // a CertAuthority error).
473
- Err ( latent_errors. pop ( ) . unwrap ( ) )
474
463
}
475
464
}
476
465
0 commit comments