@@ -7,6 +7,7 @@ use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
7
7
use rustc_error_codes:: * ;
8
8
use syntax:: ast:: { self , DUMMY_NODE_ID , Ident , Attribute , AttrKind , AttrStyle , AnonConst , Item } ;
9
9
use syntax:: ast:: { ItemKind , ImplItem , ImplItemKind , TraitItem , TraitItemKind , UseTree , UseTreeKind } ;
10
+ use syntax:: ast:: { AssocItemKind } ;
10
11
use syntax:: ast:: { PathSegment , IsAuto , Constness , IsAsync , Unsafety , Defaultness , Extern , StrLit } ;
11
12
use syntax:: ast:: { Visibility , VisibilityKind , Mutability , FnHeader , ForeignItem , ForeignItemKind } ;
12
13
use syntax:: ast:: { Ty , TyKind , Generics , TraitRef , EnumDef , Variant , VariantData , StructField } ;
@@ -699,7 +700,7 @@ impl<'a> Parser<'a> {
699
700
let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
700
701
self . parse_impl_assoc_ty ( ) ?
701
702
} else if self . is_const_item ( ) {
702
- self . parse_impl_const ( ) ?
703
+ self . parse_assoc_const ( ) ?
703
704
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "impl" , Some ( & vis) , at_end) ? {
704
705
// FIXME: code copied from `parse_macro_use_or_failure` -- use abstraction!
705
706
( Ident :: invalid ( ) , ast:: ImplItemKind :: Macro ( mac) , Generics :: default ( ) )
@@ -749,22 +750,6 @@ impl<'a> Parser<'a> {
749
750
!self . is_keyword_ahead ( 1 , & [ kw:: Fn , kw:: Unsafe ] )
750
751
}
751
752
752
- /// This parses the grammar:
753
- /// ImplItemConst = "const" Ident ":" Ty "=" Expr ";"
754
- fn parse_impl_const ( & mut self ) -> PResult < ' a , ( Ident , ImplItemKind , Generics ) > {
755
- self . expect_keyword ( kw:: Const ) ?;
756
- let ident = self . parse_ident ( ) ?;
757
- self . expect ( & token:: Colon ) ?;
758
- let ty = self . parse_ty ( ) ?;
759
- let expr = if self . eat ( & token:: Eq ) {
760
- Some ( self . parse_expr ( ) ?)
761
- } else {
762
- None
763
- } ;
764
- self . expect_semi ( ) ?;
765
- Ok ( ( ident, ImplItemKind :: Const ( ty, expr) , Generics :: default ( ) ) )
766
- }
767
-
768
753
/// Parses the following grammar:
769
754
///
770
755
/// AssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty]
@@ -911,7 +896,7 @@ impl<'a> Parser<'a> {
911
896
let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
912
897
self . parse_trait_item_assoc_ty ( ) ?
913
898
} else if self . is_const_item ( ) {
914
- self . parse_trait_item_const ( ) ?
899
+ self . parse_assoc_const ( ) ?
915
900
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "trait" , None , & mut false ) ? {
916
901
// trait item macro.
917
902
( Ident :: invalid ( ) , TraitItemKind :: Macro ( mac) , Generics :: default ( ) )
@@ -932,7 +917,10 @@ impl<'a> Parser<'a> {
932
917
} )
933
918
}
934
919
935
- fn parse_trait_item_const ( & mut self ) -> PResult < ' a , ( Ident , TraitItemKind , Generics ) > {
920
+ /// This parses the grammar:
921
+ ///
922
+ /// AssocConst = "const" Ident ":" Ty "=" Expr ";"
923
+ fn parse_assoc_const ( & mut self ) -> PResult < ' a , ( Ident , AssocItemKind , Generics ) > {
936
924
self . expect_keyword ( kw:: Const ) ?;
937
925
let ident = self . parse_ident ( ) ?;
938
926
self . expect ( & token:: Colon ) ?;
@@ -943,7 +931,7 @@ impl<'a> Parser<'a> {
943
931
None
944
932
} ;
945
933
self . expect_semi ( ) ?;
946
- Ok ( ( ident, TraitItemKind :: Const ( ty, expr) , Generics :: default ( ) ) )
934
+ Ok ( ( ident, AssocItemKind :: Const ( ty, expr) , Generics :: default ( ) ) )
947
935
}
948
936
949
937
/// Parses the following grammar:
0 commit comments