Skip to content

Commit d8aeaba

Browse files
ytmimicalebcartwright
authored andcommitted
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.
1 parent 641d4f5 commit d8aeaba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/matches.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,18 @@ fn rewrite_match_arm(
246246
};
247247

248248
// Patterns
249-
// 5 = ` => {`
250-
let pat_shape = shape.sub_width(5)?.offset_left(pipe_offset)?;
249+
let pat_shape = match &arm.body.kind {
250+
ast::ExprKind::Block(_, Some(label)) => {
251+
// Some block with a label ` => 'label: {`
252+
// 7 = ` => : {`
253+
let label_len = label.ident.as_str().len();
254+
shape.sub_width(7 + label_len)?.offset_left(pipe_offset)?
255+
}
256+
_ => {
257+
// 5 = ` => {`
258+
shape.sub_width(5)?.offset_left(pipe_offset)?
259+
}
260+
};
251261
let pats_str = arm.pat.rewrite(context, pat_shape)?;
252262

253263
// Guard

0 commit comments

Comments
 (0)