Skip to content

Commit

Permalink
Pretty print break and continue without redundant space
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 5, 2021
1 parent 772d51f commit abb8893
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,22 +2127,20 @@ impl<'a> State<'a> {
ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true),
ast::ExprKind::Break(opt_label, ref opt_expr) => {
self.s.word("break");
self.s.space();
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.s.space();
self.print_ident(label.ident);
}
if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.s.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
}
ast::ExprKind::Continue(opt_label) => {
self.s.word("continue");
self.s.space();
if let Some(label) = opt_label {
self.s.space();
self.print_ident(label.ident);
self.s.space()
}
}
ast::ExprKind::Ret(ref result) => {
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,22 +1600,20 @@ impl<'a> State<'a> {
hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true),
hir::ExprKind::Break(destination, ref opt_expr) => {
self.s.word("break");
self.s.space();
if let Some(label) = destination.label {
self.print_ident(label.ident);
self.s.space();
self.print_ident(label.ident);
}
if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.s.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
}
hir::ExprKind::Continue(destination) => {
self.s.word("continue");
self.s.space();
if let Some(label) = destination.label {
self.s.space();
self.print_ident(label.ident);
self.s.space()
}
}
hir::ExprKind::Ret(ref result) => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/pretty/ast-stmt-expr-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ fn syntax() {
let _ = #[attr] &mut 0;
let _ = #[attr] &#[attr] 0;
let _ = #[attr] &mut #[attr] 0;
let _ = #[attr] break ;
let _ = #[attr] continue ;
let _ = #[attr] break;
let _ = #[attr] continue;
let _ = #[attr] return;
let _ = #[attr] foo!();
let _ = #[attr] foo!(#! [attr]);
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/hir-pretty-loop.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// pretty-mode:hir
// pp-exact:hir-pretty-loop.pp

pub fn foo() { loop { break ; } }
pub fn foo() { loop { break; } }
5 changes: 2 additions & 3 deletions src/test/pretty/stmt_expr_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ fn _11() {
let _ = #[rustc_dummy] &mut 0;
let _ = #[rustc_dummy] &#[rustc_dummy] 0;
let _ = #[rustc_dummy] &mut #[rustc_dummy] 0;
// FIXME: pp bug, extra space after keyword?
while false { let _ = #[rustc_dummy] continue ; }
while true { let _ = #[rustc_dummy] break ; }
while false { let _ = #[rustc_dummy] continue; }
while true { let _ = #[rustc_dummy] break; }
|| #[rustc_dummy] return;
let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![];
Expand Down

0 comments on commit abb8893

Please sign in to comment.