mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 04:55:09 +00:00
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:
parent
2e1754e5fc
commit
1df7e9831b
162 changed files with 344 additions and 476 deletions
|
@ -830,11 +830,11 @@ fn handle_slice_comments<'a>(
|
|||
fn handle_leading_function_with_decorators_comment(comment: DecoratedComment) -> CommentPlacement {
|
||||
let is_preceding_decorator = comment
|
||||
.preceding_node()
|
||||
.map_or(false, |node| node.is_decorator());
|
||||
.is_some_and(|node| node.is_decorator());
|
||||
|
||||
let is_following_arguments = comment
|
||||
.following_node()
|
||||
.map_or(false, |node| node.is_arguments());
|
||||
.is_some_and(|node| node.is_arguments());
|
||||
|
||||
if comment.line_position().is_own_line() && is_preceding_decorator && is_following_arguments {
|
||||
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||
|
@ -1237,7 +1237,7 @@ fn are_same_optional<'a, T>(left: AnyNodeRef, right: Option<T>) -> bool
|
|||
where
|
||||
T: Into<AnyNodeRef<'a>>,
|
||||
{
|
||||
right.map_or(false, |right| left.ptr_eq(right.into()))
|
||||
right.is_some_and(|right| left.ptr_eq(right.into()))
|
||||
}
|
||||
|
||||
/// The last child of the last branch, if the node hs multiple branches.
|
||||
|
|
|
@ -101,7 +101,7 @@ pub(super) fn is_multiline_string(constant: &ExprConstant, source: &str) -> bool
|
|||
let quotes =
|
||||
StringQuotes::parse(&contents[TextRange::new(prefix.text_len(), contents.text_len())]);
|
||||
|
||||
quotes.map_or(false, StringQuotes::is_triple) && contents.contains(['\n', '\r'])
|
||||
quotes.is_some_and(StringQuotes::is_triple) && contents.contains(['\n', '\r'])
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -422,10 +422,10 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
|
|||
// Only use the layout if the first or last expression has parentheses of some sort.
|
||||
let first_parenthesized = self
|
||||
.first
|
||||
.map_or(false, |first| has_parentheses(first, self.source));
|
||||
.is_some_and(|first| has_parentheses(first, self.source));
|
||||
let last_parenthesized = self
|
||||
.last
|
||||
.map_or(false, |last| has_parentheses(last, self.source));
|
||||
.is_some_and(|last| has_parentheses(last, self.source));
|
||||
first_parenthesized || last_parenthesized
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue