@@ -1198,88 +1198,86 @@ impl<'a> Parser<'a> {
11981198 } ;
11991199 ( ident, TraitItemKind :: Const ( ty, default) )
12001200 } 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 ) ?;
12061206
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+ }
12151215
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 ;
12351233 }
1234+ _ => self . bump ( ) ,
12361235 }
1237-
1238- return Err ( e) ;
12391236 }
1240- } ;
12411237
1242- let ident = self . parse_ident ( ) ?;
1243- let mut generics = self . parse_generics ( ) ?;
1238+ return Err ( e) ;
1239+ }
1240+ } ;
12441241
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 ( ) ?;
12511244
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+ } ) ?;
12601251
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+ } ;
12741260
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+ }
12821277 } ;
1278+ ( ident, ast:: TraitItemKind :: Method ( sig, body) )
1279+ } ;
1280+
12831281 Ok ( TraitItem {
12841282 id : ast:: DUMMY_NODE_ID ,
12851283 ident : name,
@@ -3562,39 +3560,37 @@ impl<'a> Parser<'a> {
35623560 let lo = self . span . lo ;
35633561 let pat;
35643562 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) ;
35763591 }
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- _ => {
35963592 // At this point, token != _, &, &&, (, [
3597- if self . eat_keyword ( keywords:: Mut ) {
3593+ _ => if self . eat_keyword ( keywords:: Mut ) {
35983594 // Parse mut ident @ pat
35993595 pat = self . parse_pat_ident ( BindingMode :: ByValue ( Mutability :: Mutable ) ) ?;
36003596 } else if self . eat_keyword ( keywords:: Ref ) {
@@ -3605,51 +3601,49 @@ impl<'a> Parser<'a> {
36053601 // Parse box pat
36063602 let subpat = self . parse_pat ( ) ?;
36073603 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) ?;
36083615 } else if self . token . is_path_start ( ) {
36093616 // 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)
36203621 } 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 ( ) => {
36323627 // Parse macro invocation
36333628 self . bump ( ) ;
36343629 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 => {
36433637 // Parse range
36443638 let hi = self . last_span . hi ;
36453639 let begin =
36463640 self . mk_expr ( lo, hi, ExprKind :: Path ( qself, path) , ThinVec :: new ( ) ) ;
36473641 self . bump ( ) ;
36483642 let end = self . parse_pat_range_end ( ) ?;
36493643 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 ( ) {
36533647 return Err ( self . fatal ( "unexpected `{` after qualified path" ) ) ;
36543648 }
36553649 // Parse struct pattern
@@ -3661,8 +3655,8 @@ impl<'a> Parser<'a> {
36613655 } ) ;
36623656 self . bump ( ) ;
36633657 pat = PatKind :: Struct ( path, fields, etc) ;
3664- }
3665- token:: OpenDelim ( token:: Paren ) => {
3658+ }
3659+ token:: OpenDelim ( token:: Paren ) => {
36663660 if qself. is_some ( ) {
36673661 return Err ( self . fatal ( "unexpected `(` after qualified path" ) ) ;
36683662 }
@@ -3671,11 +3665,8 @@ impl<'a> Parser<'a> {
36713665 let ( fields, ddpos) = self . parse_pat_tuple_elements ( false ) ?;
36723666 self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
36733667 pat = PatKind :: TupleStruct ( path, fields, ddpos)
3674- }
3675- _ => {
3676- pat = PatKind :: Path ( qself, path) ;
3677- }
36783668 }
3669+ _ => pat = PatKind :: Path ( qself, path) ,
36793670 }
36803671 } else {
36813672 // Try to parse everything else as literal with optional minus
@@ -3695,7 +3686,6 @@ impl<'a> Parser<'a> {
36953686 }
36963687 }
36973688 }
3698- }
36993689 }
37003690
37013691 let hi = self . last_span . hi ;
0 commit comments