Rename CommentPlacement#then_with to or_else (#6341)

Per nits in the PR.
This commit is contained in:
Charlie Marsh 2023-08-04 09:50:57 -04:00 committed by GitHub
parent 1e3fe67ca5
commit 3a985dd71e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -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.

View file

@ -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<F: FnOnce(DecoratedComment<'a>) -> Self>(self, f: F) -> Self {
pub(super) fn or_else<F: FnOnce(DecoratedComment<'a>) -> Self>(self, f: F) -> Self {
match self {
Self::Default(comment) => f(comment),
_ => self,