Indent for multiline | patterns

This commit is contained in:
Richard Feldman 2022-07-03 22:17:13 -04:00
parent 872efa9724
commit 244a501433
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 21 additions and 17 deletions

View file

@ -162,10 +162,6 @@ impl<'a> Formattable for Pattern<'a> {
// Space
SpaceBefore(sub_pattern, spaces) => {
if has_inline_comment(spaces.iter()) {
buf.spaces(1);
}
if !sub_pattern.is_multiline() {
fmt_comments_only(buf, spaces.iter(), NewlineAt::Bottom, indent)
} else {
@ -177,7 +173,7 @@ impl<'a> Formattable for Pattern<'a> {
SpaceAfter(sub_pattern, spaces) => {
sub_pattern.format_with_options(buf, parens, newlines, indent);
if has_inline_comment(spaces.iter()) {
if starts_with_inline_comment(spaces.iter()) {
buf.spaces(1);
}
@ -206,8 +202,11 @@ impl<'a> Formattable for Pattern<'a> {
}
}
fn has_inline_comment<'a, I: IntoIterator<Item = &'a CommentOrNewline<'a>>>(spaces: I) -> bool {
spaces
.into_iter()
.any(|space| matches!(space, CommentOrNewline::LineComment(_)))
fn starts_with_inline_comment<'a, I: IntoIterator<Item = &'a CommentOrNewline<'a>>>(
spaces: I,
) -> bool {
match spaces.into_iter().next() {
Some(space) => matches!(space, CommentOrNewline::LineComment(_)),
None => false,
}
}