@@ -669,25 +669,6 @@ impl<'a> Parser<'a> {
669
669
Ok ( ( impl_items, attrs) )
670
670
}
671
671
672
- /// Parses an impl item.
673
- pub fn parse_impl_item ( & mut self , at_end : & mut bool ) -> PResult < ' a , AssocItem > {
674
- maybe_whole ! ( self , NtImplItem , |x| x) ;
675
- let attrs = self . parse_outer_attributes ( ) ?;
676
- let mut unclosed_delims = vec ! [ ] ;
677
- let ( mut item, tokens) = self . collect_tokens ( |this| {
678
- let item = this. parse_assoc_item ( at_end, attrs, |_| true ) ;
679
- unclosed_delims. append ( & mut this. unclosed_delims ) ;
680
- item
681
- } ) ?;
682
- self . unclosed_delims . append ( & mut unclosed_delims) ;
683
-
684
- // See `parse_item` for why this clause is here.
685
- if !item. attrs . iter ( ) . any ( |attr| attr. style == AttrStyle :: Inner ) {
686
- item. tokens = Some ( tokens) ;
687
- }
688
- Ok ( item)
689
- }
690
-
691
672
/// Parses defaultness (i.e., `default` or nothing).
692
673
fn parse_defaultness ( & mut self ) -> Defaultness {
693
674
// `pub` is included for better error messages
@@ -802,20 +783,30 @@ impl<'a> Parser<'a> {
802
783
}
803
784
}
804
785
805
- /// Parses the items in a trait declaration.
786
+ pub fn parse_impl_item ( & mut self , at_end : & mut bool ) -> PResult < ' a , AssocItem > {
787
+ maybe_whole ! ( self , NtImplItem , |x| x) ;
788
+ self . parse_assoc_item ( at_end, |_| true )
789
+ }
790
+
806
791
pub fn parse_trait_item ( & mut self , at_end : & mut bool ) -> PResult < ' a , AssocItem > {
807
792
maybe_whole ! ( self , NtTraitItem , |x| x) ;
793
+ // This is somewhat dubious; We don't want to allow
794
+ // param names to be left off if there is a definition...
795
+ //
796
+ // We don't allow param names to be left off in edition 2018.
797
+ self . parse_assoc_item ( at_end, |t| t. span . rust_2018 ( ) )
798
+ }
799
+
800
+ /// Parses associated items.
801
+ fn parse_assoc_item (
802
+ & mut self ,
803
+ at_end : & mut bool ,
804
+ is_name_required : fn ( & token:: Token ) -> bool ,
805
+ ) -> PResult < ' a , AssocItem > {
808
806
let attrs = self . parse_outer_attributes ( ) ?;
809
807
let mut unclosed_delims = vec ! [ ] ;
810
808
let ( mut item, tokens) = self . collect_tokens ( |this| {
811
- // This is somewhat dubious; We don't want to allow
812
- // param names to be left off if there is a definition...
813
- //
814
- // We don't allow param names to be left off in edition 2018.
815
- //
816
- // FIXME(Centril): bake closure into param parsing.
817
- // Also add semantic restrictions and add tests.
818
- let item = this. parse_assoc_item ( at_end, attrs, |t| t. span . rust_2018 ( ) ) ;
809
+ let item = this. parse_assoc_item_ ( at_end, attrs, is_name_required) ;
819
810
unclosed_delims. append ( & mut this. unclosed_delims ) ;
820
811
item
821
812
} ) ?;
@@ -827,7 +818,7 @@ impl<'a> Parser<'a> {
827
818
Ok ( item)
828
819
}
829
820
830
- fn parse_assoc_item (
821
+ fn parse_assoc_item_ (
831
822
& mut self ,
832
823
at_end : & mut bool ,
833
824
mut attrs : Vec < Attribute > ,
0 commit comments