format label break
This commit is contained in:
parent
26586d9de8
commit
150765d755
3 changed files with 36 additions and 3 deletions
|
@ -118,8 +118,7 @@ pub fn format_expr(
|
||||||
| ast::ExprKind::While(..)
|
| ast::ExprKind::While(..)
|
||||||
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
|
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
|
||||||
.and_then(|control_flow| control_flow.rewrite(context, shape)),
|
.and_then(|control_flow| control_flow.rewrite(context, shape)),
|
||||||
// FIXME(topecongiro): Handle label on a block (#2722).
|
ast::ExprKind::Block(ref block, opt_label) => {
|
||||||
ast::ExprKind::Block(ref block, _) => {
|
|
||||||
match expr_type {
|
match expr_type {
|
||||||
ExprType::Statement => {
|
ExprType::Statement => {
|
||||||
if is_unsafe_block(block) {
|
if is_unsafe_block(block) {
|
||||||
|
@ -131,9 +130,11 @@ pub fn format_expr(
|
||||||
rw
|
rw
|
||||||
} else {
|
} else {
|
||||||
let prefix = block_prefix(context, block, shape)?;
|
let prefix = block_prefix(context, block, shape)?;
|
||||||
|
let label_string = rewrite_label(opt_label);
|
||||||
|
|
||||||
rewrite_block_with_visitor(
|
rewrite_block_with_visitor(
|
||||||
context,
|
context,
|
||||||
&prefix,
|
&format!("{}{}", &prefix, &label_string),
|
||||||
block,
|
block,
|
||||||
Some(&expr.attrs),
|
Some(&expr.attrs),
|
||||||
shape,
|
shape,
|
||||||
|
|
16
tests/source/label_break.rs
Normal file
16
tests/source/label_break.rs
Normal 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
|
||||||
|
};
|
||||||
|
}
|
16
tests/target/label_break.rs
Normal file
16
tests/target/label_break.rs
Normal 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
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue