@@ -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 ;
@@ -21,15 +21,6 @@ use log::debug;
2121use std:: mem;
2222use errors:: { PResult , Applicability , DiagnosticBuilder , DiagnosticId , StashKey } ;
2323
24- /// Whether the type alias or associated type is a concrete type or an opaque type.
25- #[ derive( Debug ) ]
26- pub ( super ) enum AliasKind {
27- /// Just a new name for the same type.
28- Weak ( P < Ty > ) ,
29- /// Only trait impls of the type will be usable, not the actual type itself.
30- OpaqueTy ( GenericBounds ) ,
31- }
32-
3324pub ( super ) type ItemInfo = ( Ident , ItemKind , Option < Vec < Attribute > > ) ;
3425
3526impl < ' a > Parser < ' a > {
@@ -266,15 +257,11 @@ impl<'a> Parser<'a> {
266257 return self . mk_item_with_info ( attrs, lo, vis, info) ;
267258 }
268259
269- if let Some ( type_) = self . eat_type ( ) {
270- let ( ident, alias, generics) = type_?;
260+ if self . eat_keyword ( kw:: Type ) {
271261 // TYPE ITEM
272- let item_ = match alias {
273- AliasKind :: Weak ( ty) => ItemKind :: TyAlias ( ty, generics) ,
274- AliasKind :: OpaqueTy ( bounds) => ItemKind :: OpaqueTy ( bounds, generics) ,
275- } ;
276- let span = lo. to ( self . prev_span ) ;
277- return Ok ( Some ( self . mk_item ( span, ident, item_, vis, attrs) ) ) ;
262+ let ( ident, ty, generics) = self . parse_type_alias ( ) ?;
263+ let kind = ItemKind :: TyAlias ( ty, generics) ;
264+ return self . mk_item_with_info ( attrs, lo, vis, ( ident, kind, None ) ) ;
278265 }
279266
280267 if self . eat_keyword ( kw:: Enum ) {
@@ -708,13 +695,9 @@ impl<'a> Parser<'a> {
708695 let lo = self . token . span ;
709696 let vis = self . parse_visibility ( false ) ?;
710697 let defaultness = self . parse_defaultness ( ) ;
711- let ( name, kind, generics) = if let Some ( type_) = self . eat_type ( ) {
712- let ( name, alias, generics) = type_?;
713- let kind = match alias {
714- AliasKind :: Weak ( typ) => ast:: ImplItemKind :: TyAlias ( typ) ,
715- AliasKind :: OpaqueTy ( bounds) => ast:: ImplItemKind :: OpaqueTy ( bounds) ,
716- } ;
717- ( name, kind, generics)
698+ let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
699+ let ( name, ty, generics) = self . parse_type_alias ( ) ?;
700+ ( name, ast:: ImplItemKind :: TyAlias ( ty) , generics)
718701 } else if self . is_const_item ( ) {
719702 self . parse_impl_const ( ) ?
720703 } else if let Some ( mac) = self . parse_assoc_macro_invoc ( "impl" , Some ( & vis) , at_end) ? {
@@ -1318,34 +1301,16 @@ impl<'a> Parser<'a> {
13181301 } )
13191302 }
13201303
1321- /// Parses `type Foo = Bar;` or returns `None`
1322- /// without modifying the parser state.
1323- fn eat_type ( & mut self ) -> Option < PResult < ' a , ( Ident , AliasKind , Generics ) > > {
1324- // This parses the grammar:
1325- // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
1326- if self . eat_keyword ( kw:: Type ) {
1327- Some ( self . parse_type_alias ( ) )
1328- } else {
1329- None
1330- }
1331- }
1332-
1333- /// Parses a type alias or opaque type.
1334- fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , AliasKind , Generics ) > {
1304+ /// Parses the grammar:
1305+ /// Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";"
1306+ fn parse_type_alias ( & mut self ) -> PResult < ' a , ( Ident , P < Ty > , Generics ) > {
13351307 let ident = self . parse_ident ( ) ?;
13361308 let mut tps = self . parse_generics ( ) ?;
13371309 tps. where_clause = self . parse_where_clause ( ) ?;
13381310 self . expect ( & token:: Eq ) ?;
1339- let alias = if self . check_keyword ( kw:: Impl ) {
1340- self . bump ( ) ;
1341- let bounds = self . parse_generic_bounds ( Some ( self . prev_span ) ) ?;
1342- AliasKind :: OpaqueTy ( bounds)
1343- } else {
1344- let ty = self . parse_ty ( ) ?;
1345- AliasKind :: Weak ( ty)
1346- } ;
1311+ let ty = self . parse_ty ( ) ?;
13471312 self . expect_semi ( ) ?;
1348- Ok ( ( ident, alias , tps) )
1313+ Ok ( ( ident, ty , tps) )
13491314 }
13501315
13511316 /// Parses an enum declaration.
0 commit comments