Replace .map_or(false, $closure) with .is_some_and(closure) (#6244)

**Summary**
[Option::is_some_and](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.is_some_and)
and
[Result::is_ok_and](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok_and)
are new methods is rust 1.70. I find them way more readable than
`.map_or(false, ...)`.

The changes are `s/.map_or(false,/.is_some_and(/g`, then manually
switching to `is_ok_and` where the value is a Result rather than an
Option.

**Test Plan** n/a^
This commit is contained in:
konsti 2023-08-01 19:29:42 +02:00 committed by GitHub
parent 2e1754e5fc
commit 1df7e9831b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
162 changed files with 344 additions and 476 deletions

View file

@ -28,7 +28,7 @@ pub(crate) fn is_native_module_file_name(module_name: &str, file_name: &Path) ->
// The file name must be that of a native module.
if !file_name
.extension()
.map_or(false, is_native_module_file_extension)
.is_some_and(is_native_module_file_extension)
{
return false;
};
@ -45,7 +45,7 @@ pub(crate) fn find_native_module(
Ok(dir_path
.read_dir()?
.flatten()
.filter(|entry| entry.file_type().map_or(false, |ft| ft.is_file()))
.filter(|entry| entry.file_type().is_ok_and(|ft| ft.is_file()))
.map(|entry| entry.path())
.find(|path| is_native_module_file_name(module_name, path)))
}

View file

@ -292,7 +292,7 @@ fn resolve_best_absolute_import<Host: host::Host>(
&& typings_import
.resolved_paths
.last()
.map_or(false, |path| path.as_os_str().is_empty())
.is_some_and(|path| path.as_os_str().is_empty())
{
if typings_import
.implicit_imports
@ -381,9 +381,10 @@ fn resolve_best_absolute_import<Host: host::Host>(
typeshed_root.display()
);
if typeshed_root != execution_environment.root {
if best_result_so_far.as_ref().map_or(false, |result| {
result.py_typed_info.is_some() && !result.is_partly_resolved
}) {
if best_result_so_far
.as_ref()
.is_some_and(|result| result.py_typed_info.is_some() && !result.is_partly_resolved)
{
return best_result_so_far;
}
}

View file

@ -81,7 +81,7 @@ fn find_site_packages_path(
if let Some(preferred_dir) = candidate_dirs.iter().find(|dir| {
dir.file_name()
.and_then(OsStr::to_str)
.map_or(false, |name| name == python_version.dir())
.is_some_and(|name| name == python_version.dir())
}) {
debug!("Found path `{}`", preferred_dir.display());
return Some(preferred_dir.join(SITE_PACKAGES));
@ -235,7 +235,7 @@ fn build_typeshed_third_party_package_map(
if inner_entry
.path()
.extension()
.map_or(false, |extension| extension == "pyi")
.is_some_and(|extension| extension == "pyi")
{
if let Some(stripped_file_name) = inner_entry
.path()