Skip to content

Commit abb8893

Browse files
committed
Pretty print break and continue without redundant space
1 parent 772d51f commit abb8893

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2127,22 +2127,20 @@ impl<'a> State<'a> {
21272127
ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true),
21282128
ast::ExprKind::Break(opt_label, ref opt_expr) => {
21292129
self.s.word("break");
2130-
self.s.space();
21312130
if let Some(label) = opt_label {
2132-
self.print_ident(label.ident);
21332131
self.s.space();
2132+
self.print_ident(label.ident);
21342133
}
21352134
if let Some(ref expr) = *opt_expr {
2136-
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
21372135
self.s.space();
2136+
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
21382137
}
21392138
}
21402139
ast::ExprKind::Continue(opt_label) => {
21412140
self.s.word("continue");
2142-
self.s.space();
21432141
if let Some(label) = opt_label {
2142+
self.s.space();
21442143
self.print_ident(label.ident);
2145-
self.s.space()
21462144
}
21472145
}
21482146
ast::ExprKind::Ret(ref result) => {

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1600,22 +1600,20 @@ impl<'a> State<'a> {
16001600
hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true),
16011601
hir::ExprKind::Break(destination, ref opt_expr) => {
16021602
self.s.word("break");
1603-
self.s.space();
16041603
if let Some(label) = destination.label {
1605-
self.print_ident(label.ident);
16061604
self.s.space();
1605+
self.print_ident(label.ident);
16071606
}
16081607
if let Some(ref expr) = *opt_expr {
1609-
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
16101608
self.s.space();
1609+
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
16111610
}
16121611
}
16131612
hir::ExprKind::Continue(destination) => {
16141613
self.s.word("continue");
1615-
self.s.space();
16161614
if let Some(label) = destination.label {
1615+
self.s.space();
16171616
self.print_ident(label.ident);
1618-
self.s.space()
16191617
}
16201618
}
16211619
hir::ExprKind::Ret(ref result) => {

Diff for: src/test/pretty/ast-stmt-expr-attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ fn syntax() {
110110
let _ = #[attr] &mut 0;
111111
let _ = #[attr] &#[attr] 0;
112112
let _ = #[attr] &mut #[attr] 0;
113-
let _ = #[attr] break ;
114-
let _ = #[attr] continue ;
113+
let _ = #[attr] break;
114+
let _ = #[attr] continue;
115115
let _ = #[attr] return;
116116
let _ = #[attr] foo!();
117117
let _ = #[attr] foo!(#! [attr]);

Diff for: src/test/pretty/hir-pretty-loop.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
// pretty-mode:hir
77
// pp-exact:hir-pretty-loop.pp
88

9-
pub fn foo() { loop { break ; } }
9+
pub fn foo() { loop { break; } }

Diff for: src/test/pretty/stmt_expr_attributes.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ fn _11() {
229229
let _ = #[rustc_dummy] &mut 0;
230230
let _ = #[rustc_dummy] &#[rustc_dummy] 0;
231231
let _ = #[rustc_dummy] &mut #[rustc_dummy] 0;
232-
// FIXME: pp bug, extra space after keyword?
233-
while false { let _ = #[rustc_dummy] continue ; }
234-
while true { let _ = #[rustc_dummy] break ; }
232+
while false { let _ = #[rustc_dummy] continue; }
233+
while true { let _ = #[rustc_dummy] break; }
235234
|| #[rustc_dummy] return;
236235
let _ = #[rustc_dummy] expr_mac!();
237236
let _ = #[rustc_dummy] expr_mac![];

0 commit comments

Comments
 (0)