Skip to content

Commit

Permalink
Reuse print_subexpression outside of expr.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 4, 2025
1 parent 505ab00 commit 5c935d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3161,7 +3161,7 @@ pub(crate) mod printing {
);
}

fn print_subexpression(
pub(crate) fn print_subexpression(
expr: &Expr,
needs_group: bool,
tokens: &mut TokenStream,
Expand Down
11 changes: 6 additions & 5 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,12 @@ pub(crate) mod printing {
self.pat.to_tokens(tokens);
if let Some(init) = &self.init {
init.eq_token.to_tokens(tokens);
if init.diverge.is_some() && classify::expr_trailing_brace(&init.expr) {
token::Paren::default().surround(tokens, |tokens| init.expr.to_tokens(tokens));
} else {
init.expr.to_tokens(tokens);
}
expr::printing::print_subexpression(
&init.expr,
init.diverge.is_some() && classify::expr_trailing_brace(&init.expr),
tokens,
FixupContext::NONE,
);
if let Some((else_token, diverge)) = &init.diverge {
else_token.to_tokens(tokens);
match &**diverge {
Expand Down

0 comments on commit 5c935d2

Please sign in to comment.