@@ -156,8 +156,7 @@ impl<'a> Parser<'a> {
156
156
self . parse_item_mod ( attrs) ?
157
157
} else if self . eat_keyword ( kw:: Type ) {
158
158
// TYPE ITEM
159
- let ( ident, ty, generics) = self . parse_type_alias ( ) ?;
160
- ( ident, ItemKind :: TyAlias ( ty, generics) )
159
+ self . parse_type_alias ( ) ?
161
160
} else if self . eat_keyword ( kw:: Enum ) {
162
161
// ENUM ITEM
163
162
self . parse_item_enum ( ) ?
@@ -676,7 +675,10 @@ impl<'a> Parser<'a> {
676
675
vis : & Visibility ,
677
676
) -> PResult < ' a , ( Ident , AssocItemKind ) > {
678
677
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
+ }
680
682
} else if self . check_fn_front_matter ( ) {
681
683
let ( ident, sig, generics, body) = self . parse_fn ( at_end, attrs, req_name) ?;
682
684
Ok ( ( ident, AssocItemKind :: Fn ( sig, generics, body) ) )
@@ -700,10 +702,12 @@ impl<'a> Parser<'a> {
700
702
}
701
703
}
702
704
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 ) > {
707
711
let ident = self . parse_ident ( ) ?;
708
712
let mut generics = self . parse_generics ( ) ?;
709
713
@@ -715,7 +719,7 @@ impl<'a> Parser<'a> {
715
719
let default = if self . eat ( & token:: Eq ) { Some ( self . parse_ty ( ) ?) } else { None } ;
716
720
self . expect_semi ( ) ?;
717
721
718
- Ok ( ( ident, AssocItemKind :: TyAlias ( generics, bounds, default) ) )
722
+ Ok ( ( ident, ItemKind :: TyAlias ( generics, bounds, default) ) )
719
723
}
720
724
721
725
/// Parses a `UseTree`.
@@ -989,18 +993,6 @@ impl<'a> Parser<'a> {
989
993
P ( Ty { kind : TyKind :: Infer , span : id. span , id : ast:: DUMMY_NODE_ID } )
990
994
}
991
995
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
-
1004
996
/// Parses an enum declaration.
1005
997
fn parse_item_enum ( & mut self ) -> PResult < ' a , ItemInfo > {
1006
998
let id = self . parse_ident ( ) ?;
0 commit comments