Skip to content

Commit 17239d9

Browse files
committed
Fix parenthesization of subexprs containing statement boundary
1 parent 527e2ea commit 17239d9

File tree

3 files changed

+304
-56
lines changed

3 files changed

+304
-56
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,22 @@ impl<'a> State<'a> {
10961096
ast::StmtKind::Item(item) => self.print_item(item),
10971097
ast::StmtKind::Expr(expr) => {
10981098
self.space_if_not_bol();
1099-
self.print_expr_outer_attr_style(expr, false, FixupContext::default());
1099+
self.print_expr_outer_attr_style(
1100+
expr,
1101+
false,
1102+
FixupContext { stmt: true, ..FixupContext::default() },
1103+
);
11001104
if classify::expr_requires_semi_to_be_stmt(expr) {
11011105
self.word(";");
11021106
}
11031107
}
11041108
ast::StmtKind::Semi(expr) => {
11051109
self.space_if_not_bol();
1106-
self.print_expr_outer_attr_style(expr, false, FixupContext::default());
1110+
self.print_expr_outer_attr_style(
1111+
expr,
1112+
false,
1113+
FixupContext { stmt: true, ..FixupContext::default() },
1114+
);
11071115
self.word(";");
11081116
}
11091117
ast::StmtKind::Empty => {
@@ -1155,7 +1163,11 @@ impl<'a> State<'a> {
11551163
ast::StmtKind::Expr(expr) if i == blk.stmts.len() - 1 => {
11561164
self.maybe_print_comment(st.span.lo());
11571165
self.space_if_not_bol();
1158-
self.print_expr_outer_attr_style(expr, false, FixupContext::default());
1166+
self.print_expr_outer_attr_style(
1167+
expr,
1168+
false,
1169+
FixupContext { stmt: true, ..FixupContext::default() },
1170+
);
11591171
self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi()));
11601172
}
11611173
_ => self.print_stmt(st),

0 commit comments

Comments
 (0)