Skip to content

Commit

Permalink
Create braces around closure body during printing if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 16, 2024
1 parent 9b60027 commit 206d897
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2993,6 +2993,8 @@ pub(crate) mod printing {
use crate::path;
#[cfg(feature = "full")]
use crate::token;
#[cfg(feature = "full")]
use crate::ty::ReturnType;
use proc_macro2::{Literal, Span, TokenStream};
use quote::{ToTokens, TokenStreamExt};

Expand Down Expand Up @@ -3135,7 +3137,13 @@ pub(crate) mod printing {
self.inputs.to_tokens(tokens);
self.or2_token.to_tokens(tokens);
self.output.to_tokens(tokens);
self.body.to_tokens(tokens);
if matches!(self.output, ReturnType::Default) || matches!(*self.body, Expr::Block(_)) {
self.body.to_tokens(tokens);
} else {
token::Brace::default().surround(tokens, |tokens| {
self.body.to_tokens(tokens);
});
}
}
}

Expand Down

0 comments on commit 206d897

Please sign in to comment.