format label break

This commit is contained in:
csmoe 2018-05-21 12:18:06 +08:00
parent 26586d9de8
commit 150765d755
3 changed files with 36 additions and 3 deletions

View File

@ -118,8 +118,7 @@ pub fn format_expr(
| ast::ExprKind::While(..)
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
.and_then(|control_flow| control_flow.rewrite(context, shape)),
// FIXME(topecongiro): Handle label on a block (#2722).
ast::ExprKind::Block(ref block, _) => {
ast::ExprKind::Block(ref block, opt_label) => {
match expr_type {
ExprType::Statement => {
if is_unsafe_block(block) {
@ -131,9 +130,11 @@ pub fn format_expr(
rw
} else {
let prefix = block_prefix(context, block, shape)?;
let label_string = rewrite_label(opt_label);
rewrite_block_with_visitor(
context,
&prefix,
&format!("{}{}", &prefix, &label_string),
block,
Some(&expr.attrs),
shape,

View File

@ -0,0 +1,16 @@
// format with label break value.
fn main() {
'empty_block: {}
let result = 'block: {
if foo() {
// comment
break 'block 1;
}
if bar() { /* comment */
break 'block 2;
}
3
};
}

View File

@ -0,0 +1,16 @@
// format with label break value.
fn main() {
{}
let result = {
if foo() {
// comment
break 'block 1;
}
if bar() {
/* comment */
break 'block 2;
}
3
};
}