@@ -104,12 +104,12 @@ impl<'a> Parser<'a> {
104
104
}
105
105
106
106
/// Parses a pattern, that may be a or-pattern (e.g. `Some(Foo | Bar)`).
107
- fn parse_pat_with_or ( & mut self , expected : Expected ) -> PResult < ' a , P < Pat > > {
107
+ fn parse_pat_with_or ( & mut self , expected : Expected , gate_or : bool ) -> PResult < ' a , P < Pat > > {
108
108
// Parse the first pattern.
109
109
let first_pat = self . parse_pat ( expected) ?;
110
110
111
- // If the next token is not a `|`, this is not an or-pattern and
112
- // we should exit here.
111
+ // If the next token is not a `|`,
112
+ // this is not an or-pattern and we should exit here.
113
113
if !self . check ( & token:: BinOp ( token:: Or ) ) {
114
114
return Ok ( first_pat)
115
115
}
@@ -124,7 +124,10 @@ impl<'a> Parser<'a> {
124
124
125
125
let or_pattern_span = lo. to ( self . prev_span ) ;
126
126
127
- self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( or_pattern_span) ;
127
+ // Feature gate the or-pattern if instructed:
128
+ if gate_or {
129
+ self . sess . gated_spans . or_patterns . borrow_mut ( ) . push ( or_pattern_span) ;
130
+ }
128
131
129
132
Ok ( self . mk_pat ( or_pattern_span, PatKind :: Or ( pats) ) )
130
133
}
@@ -145,7 +148,11 @@ impl<'a> Parser<'a> {
145
148
token:: OpenDelim ( token:: Paren ) => self . parse_pat_tuple_or_parens ( ) ?,
146
149
token:: OpenDelim ( token:: Bracket ) => {
147
150
// Parse `[pat, pat,...]` as a slice pattern.
148
- PatKind :: Slice ( self . parse_delim_comma_seq ( token:: Bracket , |p| p. parse_pat ( None ) ) ?. 0 )
151
+ let ( pats, _) = self . parse_delim_comma_seq (
152
+ token:: Bracket ,
153
+ |p| p. parse_pat_with_or ( None , true ) ,
154
+ ) ?;
155
+ PatKind :: Slice ( pats)
149
156
}
150
157
token:: DotDot => {
151
158
self . bump ( ) ;
@@ -273,7 +280,7 @@ impl<'a> Parser<'a> {
273
280
/// Parse a tuple or parenthesis pattern.
274
281
fn parse_pat_tuple_or_parens ( & mut self ) -> PResult < ' a , PatKind > {
275
282
let ( fields, trailing_comma) = self . parse_paren_comma_seq ( |p| {
276
- p. parse_pat_with_or ( None )
283
+ p. parse_pat_with_or ( None , true )
277
284
} ) ?;
278
285
279
286
// Here, `(pat,)` is a tuple pattern.
@@ -517,7 +524,7 @@ impl<'a> Parser<'a> {
517
524
err. span_label ( self . token . span , msg) ;
518
525
return Err ( err) ;
519
526
}
520
- let ( fields, _) = self . parse_paren_comma_seq ( |p| p. parse_pat_with_or ( None ) ) ?;
527
+ let ( fields, _) = self . parse_paren_comma_seq ( |p| p. parse_pat_with_or ( None , true ) ) ?;
521
528
Ok ( PatKind :: TupleStruct ( path, fields) )
522
529
}
523
530
@@ -661,7 +668,7 @@ impl<'a> Parser<'a> {
661
668
// Parsing a pattern of the form "fieldname: pat"
662
669
let fieldname = self . parse_field_name ( ) ?;
663
670
self . bump ( ) ;
664
- let pat = self . parse_pat_with_or ( None ) ?;
671
+ let pat = self . parse_pat_with_or ( None , true ) ?;
665
672
hi = pat. span ;
666
673
( pat, fieldname, false )
667
674
} else {
0 commit comments