Skip to content

Commit

Permalink
Merge pull request #1658 from dtolnay/closurebrace
Browse files Browse the repository at this point in the history
Create braces around closure body during printing if needed
  • Loading branch information
dtolnay authored May 16, 2024
2 parents 9b60027 + 206d897 commit 83ea289
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 83ea289

Please sign in to comment.