Skip to content

Commit 83ea289

Browse files
authored
Merge pull request #1658 from dtolnay/closurebrace
Create braces around closure body during printing if needed
2 parents 9b60027 + 206d897 commit 83ea289

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/expr.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,8 @@ pub(crate) mod printing {
29932993
use crate::path;
29942994
#[cfg(feature = "full")]
29952995
use crate::token;
2996+
#[cfg(feature = "full")]
2997+
use crate::ty::ReturnType;
29962998
use proc_macro2::{Literal, Span, TokenStream};
29972999
use quote::{ToTokens, TokenStreamExt};
29983000

@@ -3135,7 +3137,13 @@ pub(crate) mod printing {
31353137
self.inputs.to_tokens(tokens);
31363138
self.or2_token.to_tokens(tokens);
31373139
self.output.to_tokens(tokens);
3138-
self.body.to_tokens(tokens);
3140+
if matches!(self.output, ReturnType::Default) || matches!(*self.body, Expr::Block(_)) {
3141+
self.body.to_tokens(tokens);
3142+
} else {
3143+
token::Brace::default().surround(tokens, |tokens| {
3144+
self.body.to_tokens(tokens);
3145+
});
3146+
}
31393147
}
31403148
}
31413149

0 commit comments

Comments
 (0)