Skip to content

Commit

Permalink
Add braces around let-else's else expression if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 15, 2024
1 parent 9597ebc commit c644808
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub(crate) mod parsing {
#[cfg(feature = "printing")]
mod printing {
use crate::classify;
use crate::expr;
use crate::expr::{self, Expr};
use crate::stmt::{Block, Local, Stmt, StmtMacro};
use crate::token;
use proc_macro2::TokenStream;
Expand Down Expand Up @@ -457,7 +457,11 @@ mod printing {
}
if let Some((else_token, diverge)) = &init.diverge {
else_token.to_tokens(tokens);
diverge.to_tokens(tokens);
match &**diverge {
Expr::Block(diverge) => diverge.to_tokens(tokens),
_ => token::Brace::default()
.surround(tokens, |tokens| diverge.to_tokens(tokens)),
}
}
}
self.semi_token.to_tokens(tokens);
Expand Down

0 comments on commit c644808

Please sign in to comment.