@@ -156,8 +156,7 @@ impl<'a> Parser<'a> {
156156 self . parse_item_mod ( attrs) ?
157157 } else if self . eat_keyword ( kw:: Type ) {
158158 // TYPE ITEM
159- let ( ident, ty, generics) = self . parse_type_alias ( ) ?;
160- ( ident, ItemKind :: TyAlias ( ty, generics) )
159+ self . parse_type_alias ( ) ?
161160 } else if self . eat_keyword ( kw:: Enum ) {
162161 // ENUM ITEM
163162 self . parse_item_enum ( ) ?
@@ -676,7 +675,10 @@ impl<'a> Parser<'a> {
676675 vis : & Visibility ,
677676 ) -> PResult < ' a , ( Ident , AssocItemKind ) > {
678677 if self . eat_keyword ( kw:: Type ) {
679- self . parse_assoc_ty ( )
678+ match self . parse_type_alias ( ) ? {
679+ ( ident, ItemKind :: TyAlias ( a, b, c) ) => Ok ( ( ident, AssocItemKind :: TyAlias ( a, b, c) ) ) ,
680+ _ => unreachable ! ( ) ,
681+ }
680682 } else if self . check_fn_front_matter ( ) {
681683 let ( ident, sig, generics, body) = self . parse_fn ( at_end, attrs, req_name) ?;
682684 Ok ( ( ident, AssocItemKind :: Fn ( sig, generics, body) ) )
@@ -700,10 +702,12 @@ impl<'a> Parser<'a> {
700702 }
701703 }
702704
703- /// Parses the following grammar:
704- ///
705- /// AssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty]
706- fn parse_assoc_ty ( & mut self ) -> PResult < ' a , ( Ident , AssocItemKind ) > {
705+ /// Parses a `type` alias with the following grammar:
706+ /// ```
707+ /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ;
708+ /// ```
709+ /// The `"type"` has already been eaten.
710+ fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , ItemKind ) > {
707711 let ident = self . parse_ident ( ) ?;
708712 let mut generics = self . parse_generics ( ) ?;
709713
@@ -715,7 +719,7 @@ impl<'a> Parser<'a> {
715719 let default = if self . eat ( & token:: Eq ) { Some ( self . parse_ty ( ) ?) } else { None } ;
716720 self . expect_semi ( ) ?;
717721
718- Ok ( ( ident, AssocItemKind :: TyAlias ( generics, bounds, default) ) )
722+ Ok ( ( ident, ItemKind :: TyAlias ( generics, bounds, default) ) )
719723 }
720724
721725 /// Parses a `UseTree`.
@@ -989,18 +993,6 @@ impl<'a> Parser<'a> {
989993 P ( Ty { kind : TyKind :: Infer , span : id. span , id : ast:: DUMMY_NODE_ID } )
990994 }
991995
992- /// Parses the grammar:
993- /// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
994- fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , P < Ty > , Generics ) > {
995- let ident = self . parse_ident ( ) ?;
996- let mut tps = self . parse_generics ( ) ?;
997- tps. where_clause = self . parse_where_clause ( ) ?;
998- self . expect ( & token:: Eq ) ?;
999- let ty = self . parse_ty ( ) ?;
1000- self . expect_semi ( ) ?;
1001- Ok ( ( ident, ty, tps) )
1002- }
1003-
1004996 /// Parses an enum declaration.
1005997 fn parse_item_enum ( & mut self ) -> PResult < ' a , ItemInfo > {
1006998 let id = self . parse_ident ( ) ?;
0 commit comments