1
Fork 0

Pretty print break and continue without redundant space

This commit is contained in:
David Tolnay 2021-12-05 12:35:09 -08:00
parent e6b883c74f
commit f0f7b8d44a
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
5 changed files with 11 additions and 16 deletions

View file

@ -2135,22 +2135,20 @@ impl<'a> State<'a> {
ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true), ast::ExprKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, true),
ast::ExprKind::Break(opt_label, ref opt_expr) => { ast::ExprKind::Break(opt_label, ref opt_expr) => {
self.word("break"); self.word("break");
self.space();
if let Some(label) = opt_label { if let Some(label) = opt_label {
self.print_ident(label.ident);
self.space(); self.space();
self.print_ident(label.ident);
} }
if let Some(ref expr) = *opt_expr { if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.space(); self.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
} }
} }
ast::ExprKind::Continue(opt_label) => { ast::ExprKind::Continue(opt_label) => {
self.word("continue"); self.word("continue");
self.space();
if let Some(label) = opt_label { if let Some(label) = opt_label {
self.space();
self.print_ident(label.ident); self.print_ident(label.ident);
self.space()
} }
} }
ast::ExprKind::Ret(ref result) => { ast::ExprKind::Ret(ref result) => {

View file

@ -1543,22 +1543,20 @@ impl<'a> State<'a> {
hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true), hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true),
hir::ExprKind::Break(destination, ref opt_expr) => { hir::ExprKind::Break(destination, ref opt_expr) => {
self.word("break"); self.word("break");
self.space();
if let Some(label) = destination.label { if let Some(label) = destination.label {
self.print_ident(label.ident);
self.space(); self.space();
self.print_ident(label.ident);
} }
if let Some(ref expr) = *opt_expr { if let Some(ref expr) = *opt_expr {
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
self.space(); self.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
} }
} }
hir::ExprKind::Continue(destination) => { hir::ExprKind::Continue(destination) => {
self.word("continue"); self.word("continue");
self.space();
if let Some(label) = destination.label { if let Some(label) = destination.label {
self.space();
self.print_ident(label.ident); self.print_ident(label.ident);
self.space()
} }
} }
hir::ExprKind::Ret(ref result) => { hir::ExprKind::Ret(ref result) => {

View file

@ -229,7 +229,6 @@ fn _11() {
let _ = #[rustc_dummy] &mut 0; let _ = #[rustc_dummy] &mut 0;
let _ = #[rustc_dummy] &#[rustc_dummy] 0; let _ = #[rustc_dummy] &#[rustc_dummy] 0;
let _ = #[rustc_dummy] &mut #[rustc_dummy] 0; let _ = #[rustc_dummy] &mut #[rustc_dummy] 0;
// FIXME: pp bug, extra space after keyword?
while false { let _ = #[rustc_dummy] continue; } while false { let _ = #[rustc_dummy] continue; }
while true { let _ = #[rustc_dummy] break; } while true { let _ = #[rustc_dummy] break; }
|| #[rustc_dummy] return; || #[rustc_dummy] return;