diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index a2e66ec6fc..6f97892d0b 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -29,7 +29,7 @@ pub(super) fn place_comment<'a>( // Change comment placement depending on the node type. These can be seen as node-specific // fixups. - comment.then_with(|comment| match comment.enclosing_node() { + comment.or_else(|comment| match comment.enclosing_node() { AnyNodeRef::Parameters(arguments) => { handle_parameters_separator_comment(comment, arguments, locator) } @@ -49,7 +49,7 @@ pub(super) fn place_comment<'a>( } AnyNodeRef::Keyword(_) => handle_dict_unpacking_comment(comment, locator), AnyNodeRef::ExprDict(_) => handle_dict_unpacking_comment(comment, locator) - .then_with(|comment| handle_bracketed_end_of_line_comment(comment, locator)), + .or_else(|comment| handle_bracketed_end_of_line_comment(comment, locator)), AnyNodeRef::ExprIfExp(expr_if) => handle_expr_if_comment(comment, expr_if, locator), AnyNodeRef::ExprSlice(expr_slice) => handle_slice_comments(comment, expr_slice, locator), AnyNodeRef::ExprStarred(starred) => { @@ -270,12 +270,12 @@ fn handle_own_line_comment_around_body<'a>( // Check if we're between bodies and should attach to the following body. handle_own_line_comment_between_branches(comment, preceding, locator) - .then_with(|comment| { + .or_else(|comment| { // Otherwise, there's no following branch or the indentation is too deep, so attach to the // recursively last statement in the preceding body with the matching indentation. handle_own_line_comment_after_branch(comment, preceding, locator) }) - .then_with(|comment| { + .or_else(|comment| { // If the following node is the first in its body, and there's a non-trivia token between the // comment and the following node (like a parenthesis), then it means the comment is trailing // the preceding node, not leading the following one. diff --git a/crates/ruff_python_formatter/src/comments/visitor.rs b/crates/ruff_python_formatter/src/comments/visitor.rs index 467e777f13..9e60c5833d 100644 --- a/crates/ruff_python_formatter/src/comments/visitor.rs +++ b/crates/ruff_python_formatter/src/comments/visitor.rs @@ -663,7 +663,7 @@ impl<'a> CommentPlacement<'a> { /// /// Returns `self` when the placement is non-[`CommentPlacement::Default`]. Otherwise, calls the /// function with the comment and returns the result. - pub(super) fn then_with) -> Self>(self, f: F) -> Self { + pub(super) fn or_else) -> Self>(self, f: F) -> Self { match self { Self::Default(comment) => f(comment), _ => self,