@@ -2741,19 +2741,6 @@ impl<'tcx> TyCtxt<'tcx> {
27412741 variant. fields . iter ( ) . position ( |field| self . hygienic_eq ( ident, field. ident , variant. def_id ) )
27422742 }
27432743
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-
27572744 /// Returns `true` if the impls are the same polarity and the trait either
27582745 /// has no items or is annotated #[marker] and prevents item overrides.
27592746 pub fn impls_are_allowed_to_overlap (
@@ -2993,20 +2980,22 @@ impl<'tcx> TyCtxt<'tcx> {
29932980 }
29942981}
29952982
2996- #[ derive( Clone ) ]
2983+ #[ derive( Copy , Clone , HashStable ) ]
29972984pub struct AssocItemsIterator < ' tcx > {
2998- tcx : TyCtxt < ' tcx > ,
2999- def_ids : & ' tcx [ DefId ] ,
3000- next_index : usize ,
2985+ pub items : & ' tcx [ AssocItem ] ,
30012986}
30022987
3003- impl Iterator for AssocItemsIterator < ' _ > {
2988+ impl < ' tcx > Iterator for AssocItemsIterator < ' tcx > {
30042989 type Item = AssocItem ;
30052990
2991+ #[ inline]
30062992 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+ }
30102999 }
30113000}
30123001
0 commit comments