@@ -1198,88 +1198,86 @@ impl<'a> Parser<'a> {
1198
1198
} ;
1199
1199
( ident, TraitItemKind :: Const ( ty, default) )
1200
1200
} else if self . token . is_path_start ( ) {
1201
- // trait item macro.
1202
- // code copied from parse_macro_use_or_failure... abstraction!
1203
- let lo = self . span . lo ;
1204
- let pth = self . parse_path ( PathStyle :: Mod ) ?;
1205
- self . expect ( & token:: Not ) ?;
1201
+ // trait item macro.
1202
+ // code copied from parse_macro_use_or_failure... abstraction!
1203
+ let lo = self . span . lo ;
1204
+ let pth = self . parse_path ( PathStyle :: Mod ) ?;
1205
+ self . expect ( & token:: Not ) ?;
1206
1206
1207
- // eat a matched-delimiter token tree:
1208
- let delim = self . expect_open_delim ( ) ?;
1209
- let tts = self . parse_seq_to_end ( & token:: CloseDelim ( delim) ,
1210
- SeqSep :: none ( ) ,
1211
- |pp| pp. parse_token_tree ( ) ) ?;
1212
- if delim != token:: Brace {
1213
- self . expect ( & token:: Semi ) ?
1214
- }
1207
+ // eat a matched-delimiter token tree:
1208
+ let delim = self . expect_open_delim ( ) ?;
1209
+ let tts = self . parse_seq_to_end ( & token:: CloseDelim ( delim) ,
1210
+ SeqSep :: none ( ) ,
1211
+ |pp| pp. parse_token_tree ( ) ) ?;
1212
+ if delim != token:: Brace {
1213
+ self . expect ( & token:: Semi ) ?
1214
+ }
1215
1215
1216
- let mac = spanned ( lo, self . last_span . hi , Mac_ { path : pth, tts : tts } ) ;
1217
- ( keywords:: Invalid . ident ( ) , ast:: TraitItemKind :: Macro ( mac) )
1218
- } else {
1219
- let ( constness, unsafety, abi) = match self . parse_fn_front_matter ( ) {
1220
- Ok ( cua) => cua,
1221
- Err ( e) => {
1222
- loop {
1223
- match self . token {
1224
- token:: Eof => break ,
1225
- token:: CloseDelim ( token:: Brace ) |
1226
- token:: Semi => {
1227
- self . bump ( ) ;
1228
- break ;
1229
- }
1230
- token:: OpenDelim ( token:: Brace ) => {
1231
- self . parse_token_tree ( ) ?;
1232
- break ;
1233
- }
1234
- _ => self . bump ( )
1216
+ let mac = spanned ( lo, self . last_span . hi , Mac_ { path : pth, tts : tts } ) ;
1217
+ ( keywords:: Invalid . ident ( ) , ast:: TraitItemKind :: Macro ( mac) )
1218
+ } else {
1219
+ let ( constness, unsafety, abi) = match self . parse_fn_front_matter ( ) {
1220
+ Ok ( cua) => cua,
1221
+ Err ( e) => {
1222
+ loop {
1223
+ match self . token {
1224
+ token:: Eof => break ,
1225
+ token:: CloseDelim ( token:: Brace ) |
1226
+ token:: Semi => {
1227
+ self . bump ( ) ;
1228
+ break ;
1229
+ }
1230
+ token:: OpenDelim ( token:: Brace ) => {
1231
+ self . parse_token_tree ( ) ?;
1232
+ break ;
1235
1233
}
1234
+ _ => self . bump ( ) ,
1236
1235
}
1237
-
1238
- return Err ( e) ;
1239
1236
}
1240
- } ;
1241
1237
1242
- let ident = self . parse_ident ( ) ?;
1243
- let mut generics = self . parse_generics ( ) ?;
1238
+ return Err ( e) ;
1239
+ }
1240
+ } ;
1244
1241
1245
- let d = self . parse_fn_decl_with_self ( |p : & mut Parser < ' a > |{
1246
- // This is somewhat dubious; We don't want to allow
1247
- // argument names to be left off if there is a
1248
- // definition...
1249
- p. parse_arg_general ( false )
1250
- } ) ?;
1242
+ let ident = self . parse_ident ( ) ?;
1243
+ let mut generics = self . parse_generics ( ) ?;
1251
1244
1252
- generics. where_clause = self . parse_where_clause ( ) ?;
1253
- let sig = ast:: MethodSig {
1254
- unsafety : unsafety,
1255
- constness : constness,
1256
- decl : d,
1257
- generics : generics,
1258
- abi : abi,
1259
- } ;
1245
+ let d = self . parse_fn_decl_with_self ( |p : & mut Parser < ' a > |{
1246
+ // This is somewhat dubious; We don't want to allow
1247
+ // argument names to be left off if there is a
1248
+ // definition...
1249
+ p. parse_arg_general ( false )
1250
+ } ) ?;
1260
1251
1261
- let body = match self . token {
1262
- token:: Semi => {
1263
- self . bump ( ) ;
1264
- debug ! ( "parse_trait_methods(): parsing required method" ) ;
1265
- None
1266
- }
1267
- token:: OpenDelim ( token:: Brace ) => {
1268
- debug ! ( "parse_trait_methods(): parsing provided method" ) ;
1269
- let ( inner_attrs, body) =
1270
- self . parse_inner_attrs_and_block ( ) ?;
1271
- attrs. extend ( inner_attrs. iter ( ) . cloned ( ) ) ;
1272
- Some ( body)
1273
- }
1252
+ generics. where_clause = self . parse_where_clause ( ) ?;
1253
+ let sig = ast:: MethodSig {
1254
+ unsafety : unsafety,
1255
+ constness : constness,
1256
+ decl : d,
1257
+ generics : generics,
1258
+ abi : abi,
1259
+ } ;
1274
1260
1275
- _ => {
1276
- let token_str = self . this_token_to_string ( ) ;
1277
- return Err ( self . fatal ( & format ! ( "expected `;` or `{{`, found `{}`" ,
1278
- token_str) [ ..] ) )
1279
- }
1280
- } ;
1281
- ( ident, ast:: TraitItemKind :: Method ( sig, body) )
1261
+ let body = match self . token {
1262
+ token:: Semi => {
1263
+ self . bump ( ) ;
1264
+ debug ! ( "parse_trait_methods(): parsing required method" ) ;
1265
+ None
1266
+ }
1267
+ token:: OpenDelim ( token:: Brace ) => {
1268
+ debug ! ( "parse_trait_methods(): parsing provided method" ) ;
1269
+ let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
1270
+ attrs. extend ( inner_attrs. iter ( ) . cloned ( ) ) ;
1271
+ Some ( body)
1272
+ }
1273
+ _ => {
1274
+ let token_str = self . this_token_to_string ( ) ;
1275
+ return Err ( self . fatal ( & format ! ( "expected `;` or `{{`, found `{}`" , token_str) ) ) ;
1276
+ }
1282
1277
} ;
1278
+ ( ident, ast:: TraitItemKind :: Method ( sig, body) )
1279
+ } ;
1280
+
1283
1281
Ok ( TraitItem {
1284
1282
id : ast:: DUMMY_NODE_ID ,
1285
1283
ident : name,
@@ -3562,39 +3560,37 @@ impl<'a> Parser<'a> {
3562
3560
let lo = self . span . lo ;
3563
3561
let pat;
3564
3562
match self . token {
3565
- token:: Underscore => {
3566
- // Parse _
3567
- self . bump ( ) ;
3568
- pat = PatKind :: Wild ;
3569
- }
3570
- token:: BinOp ( token:: And ) | token:: AndAnd => {
3571
- // Parse &pat / &mut pat
3572
- self . expect_and ( ) ?;
3573
- let mutbl = self . parse_mutability ( ) ?;
3574
- if let token:: Lifetime ( ident) = self . token {
3575
- return Err ( self . fatal ( & format ! ( "unexpected lifetime `{}` in pattern" , ident) ) ) ;
3563
+ token:: Underscore => {
3564
+ // Parse _
3565
+ self . bump ( ) ;
3566
+ pat = PatKind :: Wild ;
3567
+ }
3568
+ token:: BinOp ( token:: And ) | token:: AndAnd => {
3569
+ // Parse &pat / &mut pat
3570
+ self . expect_and ( ) ?;
3571
+ let mutbl = self . parse_mutability ( ) ?;
3572
+ if let token:: Lifetime ( ident) = self . token {
3573
+ return Err ( self . fatal ( & format ! ( "unexpected lifetime `{}` in pattern" , ident) ) ) ;
3574
+ }
3575
+ let subpat = self . parse_pat ( ) ?;
3576
+ pat = PatKind :: Ref ( subpat, mutbl) ;
3577
+ }
3578
+ token:: OpenDelim ( token:: Paren ) => {
3579
+ // Parse (pat,pat,pat,...) as tuple pattern
3580
+ self . bump ( ) ;
3581
+ let ( fields, ddpos) = self . parse_pat_tuple_elements ( true ) ?;
3582
+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
3583
+ pat = PatKind :: Tuple ( fields, ddpos) ;
3584
+ }
3585
+ token:: OpenDelim ( token:: Bracket ) => {
3586
+ // Parse [pat,pat,...] as slice pattern
3587
+ self . bump ( ) ;
3588
+ let ( before, slice, after) = self . parse_pat_vec_elements ( ) ?;
3589
+ self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
3590
+ pat = PatKind :: Vec ( before, slice, after) ;
3576
3591
}
3577
-
3578
- let subpat = self . parse_pat ( ) ?;
3579
- pat = PatKind :: Ref ( subpat, mutbl) ;
3580
- }
3581
- token:: OpenDelim ( token:: Paren ) => {
3582
- // Parse (pat,pat,pat,...) as tuple pattern
3583
- self . bump ( ) ;
3584
- let ( fields, ddpos) = self . parse_pat_tuple_elements ( true ) ?;
3585
- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
3586
- pat = PatKind :: Tuple ( fields, ddpos) ;
3587
- }
3588
- token:: OpenDelim ( token:: Bracket ) => {
3589
- // Parse [pat,pat,...] as slice pattern
3590
- self . bump ( ) ;
3591
- let ( before, slice, after) = self . parse_pat_vec_elements ( ) ?;
3592
- self . expect ( & token:: CloseDelim ( token:: Bracket ) ) ?;
3593
- pat = PatKind :: Vec ( before, slice, after) ;
3594
- }
3595
- _ => {
3596
3592
// At this point, token != _, &, &&, (, [
3597
- if self . eat_keyword ( keywords:: Mut ) {
3593
+ _ => if self . eat_keyword ( keywords:: Mut ) {
3598
3594
// Parse mut ident @ pat
3599
3595
pat = self . parse_pat_ident ( BindingMode :: ByValue ( Mutability :: Mutable ) ) ?;
3600
3596
} else if self . eat_keyword ( keywords:: Ref ) {
@@ -3605,51 +3601,49 @@ impl<'a> Parser<'a> {
3605
3601
// Parse box pat
3606
3602
let subpat = self . parse_pat ( ) ?;
3607
3603
pat = PatKind :: Box ( subpat) ;
3604
+ } else if self . token . is_ident ( ) && self . token . is_path_start ( ) &&
3605
+ self . look_ahead ( 1 , |t| match * t {
3606
+ token:: OpenDelim ( token:: Paren ) | token:: OpenDelim ( token:: Brace ) |
3607
+ token:: DotDotDot | token:: ModSep | token:: Not => false ,
3608
+ _ => true ,
3609
+ } ) {
3610
+ // Parse ident @ pat
3611
+ // This can give false positives and parse nullary enums,
3612
+ // they are dealt with later in resolve
3613
+ let binding_mode = BindingMode :: ByValue ( Mutability :: Immutable ) ;
3614
+ pat = self . parse_pat_ident ( binding_mode) ?;
3608
3615
} else if self . token . is_path_start ( ) {
3609
3616
// Parse pattern starting with a path
3610
- if self . token . is_ident ( ) && self . look_ahead ( 1 , |t| match * t {
3611
- token:: OpenDelim ( token:: Paren ) | token:: OpenDelim ( token:: Brace ) |
3612
- token:: DotDotDot | token:: ModSep | token:: Not => false ,
3613
- _ => true ,
3614
- } ) {
3615
- // Parse ident @ pat
3616
- // This can give false positives and parse nullary enums,
3617
- // they are dealt with later in resolve
3618
- let binding_mode = BindingMode :: ByValue ( Mutability :: Immutable ) ;
3619
- pat = self . parse_pat_ident ( binding_mode) ?;
3617
+ let ( qself, path) = if self . eat_lt ( ) {
3618
+ // Parse a qualified path
3619
+ let ( qself, path) = self . parse_qualified_path ( PathStyle :: Expr ) ?;
3620
+ ( Some ( qself) , path)
3620
3621
} else {
3621
- let ( qself, path) = if self . eat_lt ( ) {
3622
- // Parse a qualified path
3623
- let ( qself, path) =
3624
- self . parse_qualified_path ( PathStyle :: Expr ) ?;
3625
- ( Some ( qself) , path)
3626
- } else {
3627
- // Parse an unqualified path
3628
- ( None , self . parse_path ( PathStyle :: Expr ) ?)
3629
- } ;
3630
- match self . token {
3631
- token:: Not if qself. is_none ( ) => {
3622
+ // Parse an unqualified path
3623
+ ( None , self . parse_path ( PathStyle :: Expr ) ?)
3624
+ } ;
3625
+ match self . token {
3626
+ token:: Not if qself. is_none ( ) => {
3632
3627
// Parse macro invocation
3633
3628
self . bump ( ) ;
3634
3629
let delim = self . expect_open_delim ( ) ?;
3635
- let tts = self . parse_seq_to_end (
3636
- & token:: CloseDelim ( delim) ,
3637
- SeqSep :: none ( ) , |p| p. parse_token_tree ( ) ) ?;
3638
- let mac = Mac_ { path : path, tts : tts } ;
3639
- pat = PatKind :: Mac ( codemap:: Spanned { node : mac,
3640
- span : mk_sp ( lo, self . last_span . hi ) } ) ;
3641
- }
3642
- token:: DotDotDot => {
3630
+ let tts = self . parse_seq_to_end ( & token:: CloseDelim ( delim) ,
3631
+ SeqSep :: none ( ) ,
3632
+ |p| p. parse_token_tree ( ) ) ?;
3633
+ let mac = spanned ( lo, self . last_span . hi , Mac_ { path : path, tts : tts } ) ;
3634
+ pat = PatKind :: Mac ( mac) ;
3635
+ }
3636
+ token:: DotDotDot => {
3643
3637
// Parse range
3644
3638
let hi = self . last_span . hi ;
3645
3639
let begin =
3646
3640
self . mk_expr ( lo, hi, ExprKind :: Path ( qself, path) , ThinVec :: new ( ) ) ;
3647
3641
self . bump ( ) ;
3648
3642
let end = self . parse_pat_range_end ( ) ?;
3649
3643
pat = PatKind :: Range ( begin, end) ;
3650
- }
3651
- token:: OpenDelim ( token:: Brace ) => {
3652
- if qself. is_some ( ) {
3644
+ }
3645
+ token:: OpenDelim ( token:: Brace ) => {
3646
+ if qself. is_some ( ) {
3653
3647
return Err ( self . fatal ( "unexpected `{` after qualified path" ) ) ;
3654
3648
}
3655
3649
// Parse struct pattern
@@ -3661,8 +3655,8 @@ impl<'a> Parser<'a> {
3661
3655
} ) ;
3662
3656
self . bump ( ) ;
3663
3657
pat = PatKind :: Struct ( path, fields, etc) ;
3664
- }
3665
- token:: OpenDelim ( token:: Paren ) => {
3658
+ }
3659
+ token:: OpenDelim ( token:: Paren ) => {
3666
3660
if qself. is_some ( ) {
3667
3661
return Err ( self . fatal ( "unexpected `(` after qualified path" ) ) ;
3668
3662
}
@@ -3671,11 +3665,8 @@ impl<'a> Parser<'a> {
3671
3665
let ( fields, ddpos) = self . parse_pat_tuple_elements ( false ) ?;
3672
3666
self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
3673
3667
pat = PatKind :: TupleStruct ( path, fields, ddpos)
3674
- }
3675
- _ => {
3676
- pat = PatKind :: Path ( qself, path) ;
3677
- }
3678
3668
}
3669
+ _ => pat = PatKind :: Path ( qself, path) ,
3679
3670
}
3680
3671
} else {
3681
3672
// Try to parse everything else as literal with optional minus
@@ -3695,7 +3686,6 @@ impl<'a> Parser<'a> {
3695
3686
}
3696
3687
}
3697
3688
}
3698
- }
3699
3689
}
3700
3690
3701
3691
let hi = self . last_span . hi ;
0 commit comments