]> git.lizzy.rs Git - rust.git/commitdiff
Support parentheses in patterns
authorSeiichi Uchida <seuchida@gmail.com>
Tue, 6 Mar 2018 11:05:47 +0000 (20:05 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Tue, 6 Mar 2018 11:07:09 +0000 (20:07 +0900)
src/expr.rs
src/patterns.rs

index 337080f6c99ed00b1cbe4b3e7c430c6b7219d54e..0179d00b91984679db1a2b61ef900e1fa58a6382 100644 (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)
+        }
     }
 }
 
index 4bcf2890c35e8678b8e9cbd17706e2bee7611c25..e94f13b9daf27d77e3a6076dbda4e0d76def10cc 100644 (file)
@@ -129,6 +129,8 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                 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)),
         }
     }
 }