Skip to content

Commit

Permalink
Merge pull request #1800 from dtolnay/rightmost
Browse files Browse the repository at this point in the history
Rename subsequent_subexpression -> rightmost_subexpression
  • Loading branch information
dtolnay authored Dec 26, 2024
2 parents cf75a99 + eb0eb0c commit 4947eb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3282,7 +3282,7 @@ pub(crate) mod printing {
&e.right,
fixup.precedence(&e.right) < Precedence::Assign,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}

Expand Down Expand Up @@ -3362,7 +3362,7 @@ pub(crate) mod printing {
&e.right,
right_needs_group,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}

Expand Down Expand Up @@ -3399,7 +3399,7 @@ pub(crate) mod printing {
// ^---------------------------------^
e.label.is_none() && classify::expr_leading_label(value),
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}
}
Expand Down Expand Up @@ -3766,7 +3766,7 @@ pub(crate) mod printing {
end,
fixup.precedence(end) <= Precedence::Range,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}
}
Expand All @@ -3789,7 +3789,7 @@ pub(crate) mod printing {
&e.expr,
fixup.precedence(&e.expr) < Precedence::Prefix,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}

Expand All @@ -3808,7 +3808,7 @@ pub(crate) mod printing {
&e.expr,
fixup.precedence(&e.expr) < Precedence::Prefix,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}

Expand Down Expand Up @@ -3838,7 +3838,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
e.return_token.to_tokens(tokens);
if let Some(expr) = &e.expr {
print_expr(expr, tokens, fixup.subsequent_subexpression());
print_expr(expr, tokens, fixup.rightmost_subexpression());
}
}

Expand Down Expand Up @@ -3918,7 +3918,7 @@ pub(crate) mod printing {
&e.expr,
fixup.precedence(&e.expr) < Precedence::Prefix,
tokens,
fixup.subsequent_subexpression(),
fixup.rightmost_subexpression(),
);
}

Expand Down Expand Up @@ -3963,7 +3963,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
e.yield_token.to_tokens(tokens);
if let Some(expr) = &e.expr {
print_expr(expr, tokens, fixup.subsequent_subexpression());
print_expr(expr, tokens, fixup.rightmost_subexpression());
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,18 @@ impl FixupContext {
}
}

/// Transform this fixup into the one that should apply when printing any
/// subexpression that is neither a leftmost subexpression nor surrounded in
/// delimiters.
/// Transform this fixup into the one that should apply when printing the
/// rightmost subexpression of the current expression.
///
/// The rightmost subexpression is any subexpression that has a different
/// first token than the current expression, but has the same last token.
///
/// For example in `$a + $b` and `-$b`, the subexpression `$b` is a
/// rightmost subexpression.
///
/// This is for any subexpression that has a different first token than the
/// current expression, and is not surrounded by a paren/bracket/brace. For
/// example the `$b` in `$a + $b` and `-$b`, but not the one in `[$b]` or
/// `$a.f($b)`.
pub fn subsequent_subexpression(self) -> Self {
/// Not every expression has a rightmost subexpression. For example neither
/// `[$b]` nor `$a.f($b)` have one.
pub fn rightmost_subexpression(self) -> Self {
FixupContext {
#[cfg(feature = "full")]
stmt: false,
Expand Down

0 comments on commit 4947eb4

Please sign in to comment.