@@ -24,6 +24,7 @@ use rustc_span::source_map::{self, Span};
24
24
use rustc_span:: symbol:: { kw, sym, Symbol } ;
25
25
26
26
use log:: debug;
27
+ use std:: convert:: TryFrom ;
27
28
use std:: mem;
28
29
29
30
pub ( super ) type ItemInfo = ( Ident , ItemKind ) ;
@@ -647,16 +648,16 @@ impl<'a> Parser<'a> {
647
648
/// Parses associated items.
648
649
fn parse_assoc_item ( & mut self , req_name : ReqName ) -> PResult < ' a , Option < Option < P < AssocItem > > > > {
649
650
Ok ( self . parse_item_ ( req_name) ?. map ( |Item { attrs, id, span, vis, ident, kind, tokens } | {
650
- let kind = match kind {
651
- ItemKind :: Mac ( a ) => AssocItemKind :: Macro ( a ) ,
652
- ItemKind :: Fn ( a , b , c , d ) => AssocItemKind :: Fn ( a , b , c , d ) ,
653
- ItemKind :: TyAlias ( a, b , c , d ) => AssocItemKind :: TyAlias ( a , b , c , d ) ,
654
- ItemKind :: Const ( a , b , c ) => AssocItemKind :: Const ( a , b , c ) ,
655
- ItemKind :: Static ( a , _ , b ) => {
656
- self . struct_span_err ( span , "associated `static` items are not allowed" ) . emit ( ) ;
657
- AssocItemKind :: Const ( Defaultness :: Final , a , b )
658
- }
659
- _ => return self . error_bad_item_kind ( span , & kind , "`trait`s or `impl`s" ) ,
651
+ let kind = match AssocItemKind :: try_from ( kind) {
652
+ Ok ( kind ) => kind ,
653
+ Err ( kind ) => match kind {
654
+ ItemKind :: Static ( a, _ , b ) => {
655
+ self . struct_span_err ( span , "associated `static` items are not allowed" )
656
+ . emit ( ) ;
657
+ AssocItemKind :: Const ( Defaultness :: Final , a , b )
658
+ }
659
+ _ => return self . error_bad_item_kind ( span , & kind , "`trait`s or `impl`s" ) ,
660
+ } ,
660
661
} ;
661
662
Some ( P ( Item { attrs, id, span, vis, ident, kind, tokens } ) )
662
663
} ) )
@@ -833,16 +834,15 @@ impl<'a> Parser<'a> {
833
834
/// Parses a foreign item (one in an `extern { ... }` block).
834
835
pub fn parse_foreign_item ( & mut self ) -> PResult < ' a , Option < Option < P < ForeignItem > > > > {
835
836
Ok ( self . parse_item_ ( |_| true ) ?. map ( |Item { attrs, id, span, vis, ident, kind, tokens } | {
836
- let kind = match kind {
837
- ItemKind :: Mac ( a) => ForeignItemKind :: Macro ( a) ,
838
- ItemKind :: Fn ( a, b, c, d) => ForeignItemKind :: Fn ( a, b, c, d) ,
839
- ItemKind :: TyAlias ( a, b, c, d) => ForeignItemKind :: TyAlias ( a, b, c, d) ,
840
- ItemKind :: Static ( a, b, c) => ForeignItemKind :: Static ( a, b, c) ,
841
- ItemKind :: Const ( _, a, b) => {
842
- self . error_on_foreign_const ( span, ident) ;
843
- ForeignItemKind :: Static ( a, Mutability :: Not , b)
844
- }
845
- _ => return self . error_bad_item_kind ( span, & kind, "`extern` blocks" ) ,
837
+ let kind = match ForeignItemKind :: try_from ( kind) {
838
+ Ok ( kind) => kind,
839
+ Err ( kind) => match kind {
840
+ ItemKind :: Const ( _, a, b) => {
841
+ self . error_on_foreign_const ( span, ident) ;
842
+ ForeignItemKind :: Static ( a, Mutability :: Not , b)
843
+ }
844
+ _ => return self . error_bad_item_kind ( span, & kind, "`extern` blocks" ) ,
845
+ } ,
846
846
} ;
847
847
Some ( P ( Item { attrs, id, span, vis, ident, kind, tokens } ) )
848
848
} ) )
0 commit comments