@@ -5,7 +5,7 @@ use std::lazy::SyncOnceCell as OnceCell;
5
5
use std:: path:: PathBuf ;
6
6
use std:: rc:: Rc ;
7
7
use std:: sync:: Arc ;
8
- use std:: { slice , vec} ;
8
+ use std:: vec;
9
9
10
10
use arrayvec:: ArrayVec ;
11
11
@@ -733,43 +733,12 @@ crate struct Module {
733
733
crate span : Span ,
734
734
}
735
735
736
- crate struct ListAttributesIter < ' a > {
737
- attrs : slice:: Iter < ' a , ast:: Attribute > ,
738
- current_list : vec:: IntoIter < ast:: NestedMetaItem > ,
739
- name : Symbol ,
740
- }
741
-
742
- impl < ' a > Iterator for ListAttributesIter < ' a > {
743
- type Item = ast:: NestedMetaItem ;
744
-
745
- fn next ( & mut self ) -> Option < Self :: Item > {
746
- if let Some ( nested) = self . current_list . next ( ) {
747
- return Some ( nested) ;
748
- }
749
-
750
- for attr in & mut self . attrs {
751
- if let Some ( list) = attr. meta_item_list ( ) {
752
- if attr. has_name ( self . name ) {
753
- self . current_list = list. into_iter ( ) ;
754
- if let Some ( nested) = self . current_list . next ( ) {
755
- return Some ( nested) ;
756
- }
757
- }
758
- }
759
- }
760
-
761
- None
762
- }
763
-
764
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
765
- let lower = self . current_list . len ( ) ;
766
- ( lower, None )
767
- }
768
- }
769
-
770
736
crate trait AttributesExt {
771
- /// Finds an attribute as List and returns the list of attributes nested inside.
772
- fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > ;
737
+ type AttributeIterator < ' a > : Iterator < Item = ast:: NestedMetaItem >
738
+ where
739
+ Self : ' a ;
740
+
741
+ fn lists < ' a > ( & ' a self , name : Symbol ) -> Self :: AttributeIterator < ' a > ;
773
742
774
743
fn span ( & self ) -> Option < rustc_span:: Span > ;
775
744
@@ -781,8 +750,13 @@ crate trait AttributesExt {
781
750
}
782
751
783
752
impl AttributesExt for [ ast:: Attribute ] {
784
- fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
785
- ListAttributesIter { attrs : self . iter ( ) , current_list : Vec :: new ( ) . into_iter ( ) , name }
753
+ type AttributeIterator < ' a > = impl Iterator < Item = ast:: NestedMetaItem > + ' a ;
754
+
755
+ fn lists < ' a > ( & ' a self , name : Symbol ) -> Self :: AttributeIterator < ' a > {
756
+ self . iter ( )
757
+ . filter ( move |attr| attr. has_name ( name) )
758
+ . filter_map ( ast:: Attribute :: meta_item_list)
759
+ . flatten ( )
786
760
}
787
761
788
762
/// Return the span of the first doc-comment, if it exists.
@@ -901,12 +875,9 @@ crate trait NestedAttributesExt {
901
875
fn get_word_attr ( self , word : Symbol ) -> Option < ast:: NestedMetaItem > ;
902
876
}
903
877
904
- impl < I > NestedAttributesExt for I
905
- where
906
- I : IntoIterator < Item = ast:: NestedMetaItem > ,
907
- {
908
- fn get_word_attr ( self , word : Symbol ) -> Option < ast:: NestedMetaItem > {
909
- self . into_iter ( ) . find ( |attr| attr. is_word ( ) && attr. has_name ( word) )
878
+ impl < I : Iterator < Item = ast:: NestedMetaItem > > NestedAttributesExt for I {
879
+ fn get_word_attr ( mut self , word : Symbol ) -> Option < ast:: NestedMetaItem > {
880
+ self . find ( |attr| attr. is_word ( ) && attr. has_name ( word) )
910
881
}
911
882
}
912
883
@@ -1014,7 +985,7 @@ crate struct Attributes {
1014
985
}
1015
986
1016
987
impl Attributes {
1017
- crate fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
988
+ crate fn lists ( & self , name : Symbol ) -> impl Iterator < Item = ast :: NestedMetaItem > + ' _ {
1018
989
self . other_attrs . lists ( name)
1019
990
}
1020
991
0 commit comments