Skip to content

Commit 0ce8aa9

Browse files
committed
Remove unnecessary loop in maybe_spurious
The `anyhow` library's error already does a recursive check when we use `Error::downcast_ref`, so there's no need to explicitly do this on the `chain` of errors.
1 parent ba832ac commit 0ce8aa9

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/cargo/util/network.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,29 @@ impl<'a> Retry<'a> {
3434
}
3535

3636
fn maybe_spurious(err: &Error) -> bool {
37-
for e in err.chain() {
38-
if let Some(git_err) = e.downcast_ref::<git2::Error>() {
39-
match git_err.class() {
40-
git2::ErrorClass::Net | git2::ErrorClass::Os => return true,
41-
_ => (),
42-
}
37+
if let Some(git_err) = err.downcast_ref::<git2::Error>() {
38+
match git_err.class() {
39+
git2::ErrorClass::Net | git2::ErrorClass::Os => return true,
40+
_ => (),
4341
}
44-
if let Some(curl_err) = e.downcast_ref::<curl::Error>() {
45-
if curl_err.is_couldnt_connect()
46-
|| curl_err.is_couldnt_resolve_proxy()
47-
|| curl_err.is_couldnt_resolve_host()
48-
|| curl_err.is_operation_timedout()
49-
|| curl_err.is_recv_error()
50-
|| curl_err.is_http2_error()
51-
|| curl_err.is_http2_stream_error()
52-
|| curl_err.is_ssl_connect_error()
53-
|| curl_err.is_partial_file()
54-
{
55-
return true;
56-
}
42+
}
43+
if let Some(curl_err) = err.downcast_ref::<curl::Error>() {
44+
if curl_err.is_couldnt_connect()
45+
|| curl_err.is_couldnt_resolve_proxy()
46+
|| curl_err.is_couldnt_resolve_host()
47+
|| curl_err.is_operation_timedout()
48+
|| curl_err.is_recv_error()
49+
|| curl_err.is_http2_error()
50+
|| curl_err.is_http2_stream_error()
51+
|| curl_err.is_ssl_connect_error()
52+
|| curl_err.is_partial_file()
53+
{
54+
return true;
5755
}
58-
if let Some(not_200) = e.downcast_ref::<HttpNot200>() {
59-
if 500 <= not_200.code && not_200.code < 600 {
60-
return true;
61-
}
56+
}
57+
if let Some(not_200) = err.downcast_ref::<HttpNot200>() {
58+
if 500 <= not_200.code && not_200.code < 600 {
59+
return true;
6260
}
6361
}
6462
false

0 commit comments

Comments
 (0)