@@ -7,7 +7,7 @@ use syntax::ast::{self, Abi, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyl
77use syntax:: ast:: { ItemKind , ImplItem , ImplItemKind , TraitItem , TraitItemKind , UseTree , UseTreeKind } ;
88use syntax:: ast:: { PathSegment , IsAuto , Constness , IsAsync , Unsafety , Defaultness } ;
99use syntax:: ast:: { Visibility , VisibilityKind , Mutability , FnHeader , ForeignItem , ForeignItemKind } ;
10- use syntax:: ast:: { Ty , TyKind , Generics , GenericBounds , TraitRef , EnumDef , VariantData , StructField } ;
10+ use syntax:: ast:: { Ty , TyKind , Generics , TraitRef , EnumDef , VariantData , StructField } ;
1111use syntax:: ast:: { Mac , MacDelimiter , Block , BindingMode , FnDecl , FnSig , SelfKind , Param } ;
1212use syntax:: ptr:: P ;
1313use syntax:: ThinVec ;
@@ -24,15 +24,6 @@ use log::debug;
2424use std:: mem;
2525use errors:: { PResult , Applicability , DiagnosticBuilder , StashKey } ;
2626
27- /// Whether the type alias or associated type is a concrete type or an opaque type.
28- #[ derive( Debug ) ]
29- pub ( super ) enum AliasKind {
30- /// Just a new name for the same type.
31- Weak ( P < Ty > ) ,
32- /// Only trait impls of the type will be usable, not the actual type itself.
33- OpaqueTy ( GenericBounds ) ,
34- }
35-
3627pub ( super ) type ItemInfo = ( Ident , ItemKind , Option < Vec < Attribute > > ) ;
3728
3829impl < ' a > Parser < ' a > {
@@ -269,15 +260,11 @@ impl<'a> Parser<'a> {
269260 return self . mk_item_with_info ( attrs, lo, vis, info) ;
270261 }
271262
272- if let Some ( type_) = self . eat_type ( ) {
273- let ( ident, alias, generics) = type_?;
263+ if self . eat_keyword ( kw:: Type ) {
274264 // TYPE ITEM
275- let item_ = match alias {
276- AliasKind :: Weak ( ty) => ItemKind :: TyAlias ( ty, generics) ,
277- AliasKind :: OpaqueTy ( bounds) => ItemKind :: OpaqueTy ( bounds, generics) ,
278- } ;
279- let span = lo. to ( self . prev_span ) ;
280- return Ok ( Some ( self . mk_item ( span, ident, item_, vis, attrs) ) ) ;
265+ let ( ident, ty, generics) = self . parse_type_alias ( ) ?;
266+ let kind = ItemKind :: TyAlias ( ty, generics) ;
267+ return self . mk_item_with_info ( attrs, lo, vis, ( ident, kind, None ) ) ;
281268 }
282269
283270 if self . eat_keyword ( kw:: Enum ) {
@@ -711,13 +698,9 @@ impl<'a> Parser<'a> {
711698 let lo = self . token . span ;
712699 let vis = self . parse_visibility ( false ) ?;
713700 let defaultness = self . parse_defaultness ( ) ;
714- let ( name, kind, generics) = if let Some ( type_) = self . eat_type ( ) {
715- let ( name, alias, generics) = type_?;
716- let kind = match alias {
717- AliasKind :: Weak ( typ) => ast:: ImplItemKind :: TyAlias ( typ) ,
718- AliasKind :: OpaqueTy ( bounds) => ast:: ImplItemKind :: OpaqueTy ( bounds) ,
719- } ;
720- ( name, kind, generics)
701+ let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
702+ let ( name, ty, generics) = self . parse_type_alias ( ) ?;
703+ ( name, ast:: ImplItemKind :: TyAlias ( ty) , generics)
721704 } else if self . is_const_item ( ) {
722705 self . parse_impl_const ( ) ?
723706 } else if let Some ( mac) = self . parse_assoc_macro_invoc ( "impl" , Some ( & vis) , at_end) ? {
@@ -1322,34 +1305,16 @@ impl<'a> Parser<'a> {
13221305 } )
13231306 }
13241307
1325- /// Parses `type Foo = Bar;` or returns `None`
1326- /// without modifying the parser state.
1327- fn eat_type ( & mut self ) -> Option < PResult < ' a , ( Ident , AliasKind , Generics ) > > {
1328- // This parses the grammar:
1329- // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
1330- if self . eat_keyword ( kw:: Type ) {
1331- Some ( self . parse_type_alias ( ) )
1332- } else {
1333- None
1334- }
1335- }
1336-
1337- /// Parses a type alias or opaque type.
1338- fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , AliasKind , Generics ) > {
1308+ /// Parses the grammar:
1309+ /// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
1310+ fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , P < Ty > , Generics ) > {
13391311 let ident = self . parse_ident ( ) ?;
13401312 let mut tps = self . parse_generics ( ) ?;
13411313 tps. where_clause = self . parse_where_clause ( ) ?;
13421314 self . expect ( & token:: Eq ) ?;
1343- let alias = if self . check_keyword ( kw:: Impl ) {
1344- self . bump ( ) ;
1345- let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
1346- AliasKind :: OpaqueTy ( bounds)
1347- } else {
1348- let ty = self . parse_ty ( ) ?;
1349- AliasKind :: Weak ( ty)
1350- } ;
1315+ let ty = self . parse_ty ( ) ?;
13511316 self . expect_semi ( ) ?;
1352- Ok ( ( ident, alias , tps) )
1317+ Ok ( ( ident, ty , tps) )
13531318 }
13541319
13551320 /// Parses an enum declaration.
0 commit comments