Replace map_or(false, ..) uses with is_some_and and is_ok_and (#4703)

## Summary

Looks like there isn't a clippy lint for this yet.
This commit is contained in:
Ibraheem Ahmed 2024-07-01 15:28:42 -04:00 committed by GitHub
parent 8a2af8bc83
commit be2a67cd9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 14 additions and 21 deletions

View file

@ -1201,7 +1201,7 @@ fn calculate_row_column(content: &str, position: usize) -> (usize, usize) {
// If the next character is a newline, skip it. // If the next character is a newline, skip it.
if chars if chars
.peek() .peek()
.map_or(false, |&(_, next_char)| next_char == '\n') .is_some_and(|&(_, next_char)| next_char == '\n')
{ {
chars.next(); chars.next();
} }

View file

@ -216,7 +216,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
) )
} }
let mut end = 0; let mut end = 0;
while self.cur.get(end).copied().map_or(false, is_token_byte) { while self.cur.get(end).copied().is_some_and(is_token_byte) {
end += 1; end += 1;
} }
if end == 0 { if end == 0 {
@ -240,7 +240,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
/// ///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf /// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn maybe_parse_equals(&mut self) -> bool { fn maybe_parse_equals(&mut self) -> bool {
if self.cur.first().map_or(false, |&byte| byte == b'=') { if self.cur.first().is_some_and(|&byte| byte == b'=') {
self.cur = &self.cur[1..]; self.cur = &self.cur[1..];
true true
} else { } else {
@ -322,7 +322,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
/// ///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf /// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn maybe_parse_directive_delimiter(&mut self) -> bool { fn maybe_parse_directive_delimiter(&mut self) -> bool {
if self.cur.first().map_or(false, |&byte| byte == b',') { if self.cur.first().is_some_and(|&byte| byte == b',') {
self.cur = &self.cur[1..]; self.cur = &self.cur[1..];
true true
} else { } else {
@ -336,7 +336,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
/// ///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf /// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn skip_whitespace(&mut self) { fn skip_whitespace(&mut self) {
while self.cur.first().map_or(false, u8::is_ascii_whitespace) { while self.cur.first().is_some_and(u8::is_ascii_whitespace) {
self.cur = &self.cur[1..]; self.cur = &self.cur[1..];
} }
} }

View file

@ -201,11 +201,7 @@ pub fn directories(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
None None
} }
}) })
.filter(|entry| { .filter(|entry| entry.file_type().is_ok_and(|file_type| file_type.is_dir()))
entry
.file_type()
.map_or(false, |file_type| file_type.is_dir())
})
.map(|entry| entry.path()) .map(|entry| entry.path())
} }
@ -228,7 +224,7 @@ pub fn symlinks(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
.filter(|entry| { .filter(|entry| {
entry entry
.file_type() .file_type()
.map_or(false, |file_type| file_type.is_symlink()) .is_ok_and(|file_type| file_type.is_symlink())
}) })
.map(|entry| entry.path()) .map(|entry| entry.path())
} }
@ -249,11 +245,7 @@ pub fn files(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
None None
} }
}) })
.filter(|entry| { .filter(|entry| entry.file_type().is_ok_and(|file_type| file_type.is_file()))
entry
.file_type()
.map_or(false, |file_type| file_type.is_file())
})
.map(|entry| entry.path()) .map(|entry| entry.path())
} }

View file

@ -52,9 +52,10 @@ impl SitePackages {
.filter_map(|read_dir| match read_dir { .filter_map(|read_dir| match read_dir {
Ok(entry) => match entry.file_type() { Ok(entry) => match entry.file_type() {
Ok(file_type) => (file_type.is_dir() Ok(file_type) => (file_type.is_dir()
|| entry.path().extension().map_or(false, |ext| { || entry
ext == "egg-link" || ext == "egg-info" .path()
})) .extension()
.is_some_and(|ext| ext == "egg-link" || ext == "egg-info"))
.then_some(Ok(entry.path())), .then_some(Ok(entry.path())),
Err(err) => Some(Err(err)), Err(err) => Some(Err(err)),
}, },

View file

@ -263,7 +263,7 @@ impl InstalledToolchain {
ToolchainRequest::ExecutableName(name) => self ToolchainRequest::ExecutableName(name) => self
.executable() .executable()
.file_name() .file_name()
.map_or(false, |filename| filename.to_string_lossy() == *name), .is_some_and(|filename| filename.to_string_lossy() == *name),
ToolchainRequest::Implementation(implementation) => { ToolchainRequest::Implementation(implementation) => {
implementation == self.implementation() implementation == self.implementation()
} }

View file

@ -425,7 +425,7 @@ impl From<ExternalCommand> for RunCommand {
let target_path = PathBuf::from(&target); let target_path = PathBuf::from(&target);
if target_path if target_path
.extension() .extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("py")) .is_some_and(|ext| ext.eq_ignore_ascii_case("py"))
&& target_path.exists() && target_path.exists()
{ {
Self::Python(target_path, args.to_vec()) Self::Python(target_path, args.to_vec())