Skip to content

Commit a4c84d3

Browse files
committed
format label break
1 parent 26586d9 commit a4c84d3

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn format_expr(
119119
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
120120
.and_then(|control_flow| control_flow.rewrite(context, shape)),
121121
// FIXME(topecongiro): Handle label on a block (#2722).
122-
ast::ExprKind::Block(ref block, _) => {
122+
ast::ExprKind::Block(ref block, opt_label) => {
123123
match expr_type {
124124
ExprType::Statement => {
125125
if is_unsafe_block(block) {
@@ -131,9 +131,11 @@ pub fn format_expr(
131131
rw
132132
} else {
133133
let prefix = block_prefix(context, block, shape)?;
134+
let label_string = rewrite_label(opt_label);
135+
134136
rewrite_block_with_visitor(
135137
context,
136-
&prefix,
138+
&format!("{} {}", &prefix, &label_string),
137139
block,
138140
Some(&expr.attrs),
139141
shape,

tests/source/label_break.rs

Lines changed: 16 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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)