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 {
4848 | ast:: PatKind :: MacCall ( ..)
4949 | ast:: PatKind :: Slice ( ..)
5050 | ast:: PatKind :: Path ( ..)
51- | ast:: PatKind :: Range ( ..) => false ,
51+ | ast:: PatKind :: Range ( ..)
52+ | ast:: PatKind :: Guard ( ..) => false ,
5253 ast:: PatKind :: Tuple ( ref subpats) => subpats. len ( ) <= 1 ,
5354 ast:: PatKind :: TupleStruct ( _, ref path, ref subpats) => {
5455 path. segments . len ( ) <= 1 && subpats. len ( ) <= 1
@@ -338,8 +339,9 @@ impl Rewrite for Pat {
338339 . max_width_error ( shape. width , self . span ) ?,
339340 )
340341 . map ( |inner_pat| format ! ( "({})" , inner_pat) ) ,
341- PatKind :: Err ( _ ) => Err ( RewriteError :: Unknown ) ,
342+ PatKind :: Guard ( .. ) => Ok ( context . snippet ( self . span ) . to_string ( ) ) ,
342343 PatKind :: Deref ( _) => Err ( RewriteError :: Unknown ) ,
344+ PatKind :: Err ( _) => Err ( RewriteError :: Unknown ) ,
343345 }
344346 }
345347}
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