File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
48
48
| ast:: PatKind :: MacCall ( ..)
49
49
| ast:: PatKind :: Slice ( ..)
50
50
| ast:: PatKind :: Path ( ..)
51
- | ast:: PatKind :: Range ( ..) => false ,
51
+ | ast:: PatKind :: Range ( ..)
52
+ | ast:: PatKind :: Guard ( ..) => false ,
52
53
ast:: PatKind :: Tuple ( ref subpats) => subpats. len ( ) <= 1 ,
53
54
ast:: PatKind :: TupleStruct ( _, ref path, ref subpats) => {
54
55
path. segments . len ( ) <= 1 && subpats. len ( ) <= 1
@@ -338,8 +339,9 @@ impl Rewrite for Pat {
338
339
. max_width_error ( shape. width , self . span ) ?,
339
340
)
340
341
. map ( |inner_pat| format ! ( "({})" , inner_pat) ) ,
341
- PatKind :: Err ( _ ) => Err ( RewriteError :: Unknown ) ,
342
+ PatKind :: Guard ( .. ) => Ok ( context . snippet ( self . span ) . to_string ( ) ) ,
342
343
PatKind :: Deref ( _) => Err ( RewriteError :: Unknown ) ,
344
+ PatKind :: Err ( _) => Err ( RewriteError :: Unknown ) ,
343
345
}
344
346
}
345
347
}
Original file line number Diff line number Diff line change
1
+ #![ feature( guard_patterns) ]
2
+
3
+ fn main ( ) {
4
+ match user. subscription_plan ( ) {
5
+ ( Plan :: Regular if user. credit ( ) >= 100 ) | ( Plan :: Premium if user. credit ( ) >= 80 ) => {
6
+ // Complete the transaction.
7
+ }
8
+ _ => {
9
+ // The user doesn't have enough credit, return an error message.
10
+ }
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments