@@ -7,7 +7,7 @@ use syntax::ast::{self, Abi, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyl
7
7
use syntax:: ast:: { ItemKind , ImplItem , ImplItemKind , TraitItem , TraitItemKind , UseTree , UseTreeKind } ;
8
8
use syntax:: ast:: { PathSegment , IsAuto , Constness , IsAsync , Unsafety , Defaultness } ;
9
9
use 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 } ;
11
11
use syntax:: ast:: { Mac , MacDelimiter , Block , BindingMode , FnDecl , FnSig , SelfKind , Param } ;
12
12
use syntax:: ptr:: P ;
13
13
use syntax:: ThinVec ;
@@ -24,15 +24,6 @@ use log::debug;
24
24
use std:: mem;
25
25
use errors:: { PResult , Applicability , DiagnosticBuilder , StashKey } ;
26
26
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
-
36
27
pub ( super ) type ItemInfo = ( Ident , ItemKind , Option < Vec < Attribute > > ) ;
37
28
38
29
impl < ' a > Parser < ' a > {
@@ -269,15 +260,11 @@ impl<'a> Parser<'a> {
269
260
return self . mk_item_with_info ( attrs, lo, vis, info) ;
270
261
}
271
262
272
- if let Some ( type_) = self . eat_type ( ) {
273
- let ( ident, alias, generics) = type_?;
263
+ if self . eat_keyword ( kw:: Type ) {
274
264
// 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 ) ) ;
281
268
}
282
269
283
270
if self . eat_keyword ( kw:: Enum ) {
@@ -711,13 +698,9 @@ impl<'a> Parser<'a> {
711
698
let lo = self . token . span ;
712
699
let vis = self . parse_visibility ( false ) ?;
713
700
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)
721
704
} else if self . is_const_item ( ) {
722
705
self . parse_impl_const ( ) ?
723
706
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "impl" , Some ( & vis) , at_end) ? {
@@ -1322,34 +1305,16 @@ impl<'a> Parser<'a> {
1322
1305
} )
1323
1306
}
1324
1307
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 ) > {
1339
1311
let ident = self . parse_ident ( ) ?;
1340
1312
let mut tps = self . parse_generics ( ) ?;
1341
1313
tps. where_clause = self . parse_where_clause ( ) ?;
1342
1314
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 ( ) ?;
1351
1316
self . expect_semi ( ) ?;
1352
- Ok ( ( ident, alias , tps) )
1317
+ Ok ( ( ident, ty , tps) )
1353
1318
}
1354
1319
1355
1320
/// Parses an enum declaration.
0 commit comments