Use matches for os-error-alias (#5361)

This commit is contained in:
Charlie Marsh 2023-06-25 21:57:52 -04:00 committed by GitHub
parent fd0c3faa70
commit 19c221a2d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,21 +54,14 @@ impl AlwaysAutofixableViolation for OSErrorAlias {
}
}
const ALIASES: &[(&str, &str)] = &[
("", "EnvironmentError"),
("", "IOError"),
("", "WindowsError"),
("mmap", "error"),
("select", "error"),
("socket", "error"),
];
/// Return `true` if an [`Expr`] is an alias of `OSError`.
fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool {
semantic.resolve_call_path(expr).map_or(false, |call_path| {
ALIASES
.iter()
.any(|(module, member)| call_path.as_slice() == [*module, *member])
matches!(
call_path.as_slice(),
["", "EnvironmentError" | "IOError" | "WindowsError"]
| ["mmap" | "select" | "socket", "error"]
)
})
}