@@ -2741,19 +2741,6 @@ impl<'tcx> TyCtxt<'tcx> {
2741
2741
variant. fields . iter ( ) . position ( |field| self . hygienic_eq ( ident, field. ident , variant. def_id ) )
2742
2742
}
2743
2743
2744
- pub fn associated_items ( self , def_id : DefId ) -> AssocItemsIterator < ' tcx > {
2745
- // Ideally, we would use `-> impl Iterator` here, but it falls
2746
- // afoul of the conservative "capture [restrictions]" we put
2747
- // in place, so we use a hand-written iterator.
2748
- //
2749
- // [restrictions]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
2750
- AssocItemsIterator {
2751
- tcx : self ,
2752
- def_ids : self . associated_item_def_ids ( def_id) ,
2753
- next_index : 0 ,
2754
- }
2755
- }
2756
-
2757
2744
/// Returns `true` if the impls are the same polarity and the trait either
2758
2745
/// has no items or is annotated #[marker] and prevents item overrides.
2759
2746
pub fn impls_are_allowed_to_overlap (
@@ -2993,20 +2980,22 @@ impl<'tcx> TyCtxt<'tcx> {
2993
2980
}
2994
2981
}
2995
2982
2996
- #[ derive( Clone ) ]
2983
+ #[ derive( Copy , Clone , HashStable ) ]
2997
2984
pub struct AssocItemsIterator < ' tcx > {
2998
- tcx : TyCtxt < ' tcx > ,
2999
- def_ids : & ' tcx [ DefId ] ,
3000
- next_index : usize ,
2985
+ pub items : & ' tcx [ AssocItem ] ,
3001
2986
}
3002
2987
3003
- impl Iterator for AssocItemsIterator < ' _ > {
2988
+ impl < ' tcx > Iterator for AssocItemsIterator < ' tcx > {
3004
2989
type Item = AssocItem ;
3005
2990
2991
+ #[ inline]
3006
2992
fn next ( & mut self ) -> Option < AssocItem > {
3007
- let def_id = self . def_ids . get ( self . next_index ) ?;
3008
- self . next_index += 1 ;
3009
- Some ( self . tcx . associated_item ( * def_id) )
2993
+ if let Some ( ( first, rest) ) = self . items . split_first ( ) {
2994
+ self . items = rest;
2995
+ Some ( * first)
2996
+ } else {
2997
+ None
2998
+ }
3010
2999
}
3011
3000
}
3012
3001
0 commit comments