Skip to content

Commit 3f0b630

Browse files
committed
Support parentheses in patterns
1 parent 520f0d6 commit 3f0b630

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,9 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
15361536
ast::PatKind::TupleStruct(ref path, ref subpats, _) => {
15371537
path.segments.len() <= 1 && subpats.len() <= 1
15381538
}
1539-
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) => is_short_pattern_inner(&*p),
1539+
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
1540+
is_short_pattern_inner(&*p)
1541+
}
15401542
}
15411543
}
15421544

src/patterns.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ impl Rewrite for Pat {
129129
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
130130
}
131131
PatKind::Mac(ref mac) => rewrite_macro(mac, None, context, shape, MacroPosition::Pat),
132+
PatKind::Paren(ref pat) => pat.rewrite(context, shape.offset_left(1)?.sub_width(1)?)
133+
.map(|inner_pat| format!("({})", inner_pat)),
132134
}
133135
}
134136
}

0 commit comments

Comments
 (0)