@@ -205,46 +205,64 @@ fn tuple_pat_fields(p: &mut Parser) {
205
205
p. expect ( T ! [ ')' ] ) ;
206
206
}
207
207
208
+ // test record_pat_field
209
+ // fn foo() {
210
+ // let S { 0: 1 } = ();
211
+ // let S { x: 1 } = ();
212
+ // let S { #[cfg(any())] x: 1 } = ();
213
+ // }
214
+ fn record_pat_field ( p : & mut Parser ) {
215
+ match p. current ( ) {
216
+ IDENT | INT_NUMBER if p. nth ( 1 ) == T ! [ : ] => {
217
+ name_ref_or_index ( p) ;
218
+ p. bump ( T ! [ : ] ) ;
219
+ pattern ( p) ;
220
+ }
221
+ T ! [ . ] => {
222
+ if p. at ( T ! [ ..] ) {
223
+ p. bump ( T ! [ ..] ) ;
224
+ } else {
225
+ ident_pat ( p, false ) ;
226
+ }
227
+ }
228
+ T ! [ box] => {
229
+ // FIXME: not all box patterns should be allowed
230
+ box_pat ( p) ;
231
+ }
232
+ _ => {
233
+ ident_pat ( p, false ) ;
234
+ }
235
+ }
236
+ }
237
+
208
238
// test record_pat_field_list
209
239
// fn foo() {
210
240
// let S {} = ();
211
241
// let S { f, ref mut g } = ();
212
242
// let S { h: _, ..} = ();
213
243
// let S { h: _, } = ();
244
+ // let S { #[cfg(any())] .. } = ();
214
245
// }
215
246
fn record_pat_field_list ( p : & mut Parser ) {
216
247
assert ! ( p. at( T ![ '{' ] ) ) ;
217
248
let m = p. start ( ) ;
218
249
p. bump ( T ! [ '{' ] ) ;
219
250
while !p. at ( EOF ) && !p. at ( T ! [ '}' ] ) {
251
+ let m = p. start ( ) ;
252
+ attributes:: outer_attrs ( p) ;
253
+
220
254
match p. current ( ) {
221
255
// A trailing `..` is *not* treated as a REST_PAT.
222
- T ! [ . ] if p. at ( T ! [ ..] ) => p. bump ( T ! [ ..] ) ,
223
- T ! [ '{' ] => error_block ( p, "expected ident" ) ,
224
-
256
+ T ! [ . ] if p. at ( T ! [ ..] ) => {
257
+ p. bump ( T ! [ ..] ) ;
258
+ m. complete ( p, REST_PAT ) ;
259
+ }
260
+ T ! [ '{' ] => {
261
+ error_block ( p, "expected ident" ) ;
262
+ m. abandon ( p) ;
263
+ }
225
264
_ => {
226
- let m = p. start ( ) ;
227
- attributes:: outer_attrs ( p) ;
228
- match p. current ( ) {
229
- // test record_pat_field
230
- // fn foo() {
231
- // let S { 0: 1 } = ();
232
- // let S { x: 1 } = ();
233
- // let S { #[cfg(any())] x: 1 } = ();
234
- // }
235
- IDENT | INT_NUMBER if p. nth ( 1 ) == T ! [ : ] => {
236
- name_ref_or_index ( p) ;
237
- p. bump ( T ! [ : ] ) ;
238
- pattern ( p) ;
239
- }
240
- T ! [ box] => {
241
- // FIXME: not all box patterns should be allowed
242
- box_pat ( p) ;
243
- }
244
- _ => {
245
- ident_pat ( p, false ) ;
246
- }
247
- }
265
+ record_pat_field ( p) ;
248
266
m. complete ( p, RECORD_PAT_FIELD ) ;
249
267
}
250
268
}
0 commit comments