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

@ -132,8 +132,8 @@ where
}
}
self.start_of_line = next.as_ref().map_or(false, |lex_result| {
lex_result.as_ref().map_or(false, |(tok, _)| {
self.start_of_line = next.as_ref().is_some_and(|lex_result| {
lex_result.as_ref().is_ok_and(|(tok, _)| {
if matches!(tok, Tok::NonLogicalNewline | Tok::Comment { .. }) {
return self.start_of_line;
}

View file

@ -27,7 +27,7 @@ pub fn parse_type_annotation(
) -> Result<(Expr, AnnotationKind)> {
let expression = &source[range];
if str::raw_contents(expression).map_or(false, |body| body == value) {
if str::raw_contents(expression).is_some_and(|body| body == value) {
// The annotation is considered "simple" if and only if the raw representation (e.g.,
// `List[int]` within "List[int]") exactly matches the parsed representation. This
// isn't the case, e.g., for implicit concatenations, or for annotations that contain