@@ -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 ;
@@ -21,15 +21,6 @@ use log::debug;
21
21
use std:: mem;
22
22
use errors:: { PResult , Applicability , DiagnosticBuilder , DiagnosticId , StashKey } ;
23
23
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
-
33
24
pub ( super ) type ItemInfo = ( Ident , ItemKind , Option < Vec < Attribute > > ) ;
34
25
35
26
impl < ' a > Parser < ' a > {
@@ -266,15 +257,11 @@ impl<'a> Parser<'a> {
266
257
return self . mk_item_with_info ( attrs, lo, vis, info) ;
267
258
}
268
259
269
- if let Some ( type_) = self . eat_type ( ) {
270
- let ( ident, alias, generics) = type_?;
260
+ if self . eat_keyword ( kw:: Type ) {
271
261
// 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 ) ) ;
278
265
}
279
266
280
267
if self . eat_keyword ( kw:: Enum ) {
@@ -708,13 +695,9 @@ impl<'a> Parser<'a> {
708
695
let lo = self . token . span ;
709
696
let vis = self . parse_visibility ( false ) ?;
710
697
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)
718
701
} else if self . is_const_item ( ) {
719
702
self . parse_impl_const ( ) ?
720
703
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "impl" , Some ( & vis) , at_end) ? {
@@ -1318,34 +1301,16 @@ impl<'a> Parser<'a> {
1318
1301
} )
1319
1302
}
1320
1303
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 ) > {
1335
1307
let ident = self . parse_ident ( ) ?;
1336
1308
let mut tps = self . parse_generics ( ) ?;
1337
1309
tps. where_clause = self . parse_where_clause ( ) ?;
1338
1310
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 ( ) ?;
1347
1312
self . expect_semi ( ) ?;
1348
- Ok ( ( ident, alias , tps) )
1313
+ Ok ( ( ident, ty , tps) )
1349
1314
}
1350
1315
1351
1316
/// Parses an enum declaration.
0 commit comments