include block label length when calculating pat_shape of a match arm
Previously we alwasy assumed the match arm pattern would have `shape.width` - 5 characters of space to work with. Now if we're formatting a block expression with a label we'll take the label into account.
This commit is contained in:
parent
641d4f5898
commit
d8aeabaee1
@ -246,8 +246,18 @@ fn rewrite_match_arm(
|
||||
};
|
||||
|
||||
// Patterns
|
||||
// 5 = ` => {`
|
||||
let pat_shape = shape.sub_width(5)?.offset_left(pipe_offset)?;
|
||||
let pat_shape = match &arm.body.kind {
|
||||
ast::ExprKind::Block(_, Some(label)) => {
|
||||
// Some block with a label ` => 'label: {`
|
||||
// 7 = ` => : {`
|
||||
let label_len = label.ident.as_str().len();
|
||||
shape.sub_width(7 + label_len)?.offset_left(pipe_offset)?
|
||||
}
|
||||
_ => {
|
||||
// 5 = ` => {`
|
||||
shape.sub_width(5)?.offset_left(pipe_offset)?
|
||||
}
|
||||
};
|
||||
let pats_str = arm.pat.rewrite(context, pat_shape)?;
|
||||
|
||||
// Guard
|
||||
|
Loading…
Reference in New Issue
Block a user