Skip to content

Commit 150765d

Browse files
committed
format label break
1 parent 26586d9 commit 150765d

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/expr.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ pub fn format_expr(
118118
| ast::ExprKind::While(..)
119119
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
120120
.and_then(|control_flow| control_flow.rewrite(context, shape)),
121-
// FIXME(topecongiro): Handle label on a block (#2722).
122-
ast::ExprKind::Block(ref block, _) => {
121+
ast::ExprKind::Block(ref block, opt_label) => {
123122
match expr_type {
124123
ExprType::Statement => {
125124
if is_unsafe_block(block) {
@@ -131,9 +130,11 @@ pub fn format_expr(
131130
rw
132131
} else {
133132
let prefix = block_prefix(context, block, shape)?;
133+
let label_string = rewrite_label(opt_label);
134+
134135
rewrite_block_with_visitor(
135136
context,
136-
&prefix,
137+
&format!("{}{}", &prefix, &label_string),
137138
block,
138139
Some(&expr.attrs),
139140
shape,

tests/source/label_break.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// format with label break value.
2+
fn main() {
3+
4+
'empty_block: {}
5+
6+
let result = 'block: {
7+
if foo() {
8+
// comment
9+
break 'block 1;
10+
}
11+
if bar() { /* comment */
12+
break 'block 2;
13+
}
14+
3
15+
};
16+
}

tests/target/label_break.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// format with label break value.
2+
fn main() {
3+
{}
4+
5+
let result = {
6+
if foo() {
7+
// comment
8+
break 'block 1;
9+
}
10+
if bar() {
11+
/* comment */
12+
break 'block 2;
13+
}
14+
3
15+
};
16+
}

0 commit comments

Comments
 (0)