Support parentheses in patterns

This commit is contained in:
Seiichi Uchida 2018-03-06 20:05:47 +09:00
parent 520f0d65ef
commit 3f0b630845
2 changed files with 5 additions and 1 deletions

View File

@ -1536,7 +1536,9 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
ast::PatKind::TupleStruct(ref path, ref subpats, _) => {
path.segments.len() <= 1 && subpats.len() <= 1
}
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) => is_short_pattern_inner(&*p),
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
is_short_pattern_inner(&*p)
}
}
}

View File

@ -129,6 +129,8 @@ impl Rewrite for Pat {
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
}
PatKind::Mac(ref mac) => rewrite_macro(mac, None, context, shape, MacroPosition::Pat),
PatKind::Paren(ref pat) => pat.rewrite(context, shape.offset_left(1)?.sub_width(1)?)
.map(|inner_pat| format!("({})", inner_pat)),
}
}
}