@@ -1798,7 +1798,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
17981798 let self_ty = selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) ;
17991799
18001800 let lang_items = selcx. tcx ( ) . lang_items ( ) ;
1801- if [ lang_items. gen_trait ( ) , lang_items. future_trait ( ) ] . contains ( & Some ( trait_ref. def_id ) )
1801+ if [ lang_items. gen_trait ( ) , lang_items. future_trait ( ) , lang_items . iterator_trait ( ) ] . contains ( & Some ( trait_ref. def_id ) )
18021802 || selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_ref. def_id ) . is_some ( )
18031803 {
18041804 true
@@ -2015,6 +2015,8 @@ fn confirm_select_candidate<'cx, 'tcx>(
20152015 confirm_coroutine_candidate ( selcx, obligation, data)
20162016 } else if lang_items. future_trait ( ) == Some ( trait_def_id) {
20172017 confirm_future_candidate ( selcx, obligation, data)
2018+ } else if lang_items. iterator_trait ( ) == Some ( trait_def_id) {
2019+ confirm_iterator_candidate ( selcx, obligation, data)
20182020 } else if selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_def_id) . is_some ( ) {
20192021 if obligation. predicate . self_ty ( ) . is_closure ( ) {
20202022 confirm_closure_candidate ( selcx, obligation, data)
@@ -2135,6 +2137,50 @@ fn confirm_future_candidate<'cx, 'tcx>(
21352137 . with_addl_obligations ( obligations)
21362138}
21372139
2140+ fn confirm_iterator_candidate < ' cx , ' tcx > (
2141+ selcx : & mut SelectionContext < ' cx , ' tcx > ,
2142+ obligation : & ProjectionTyObligation < ' tcx > ,
2143+ nested : Vec < PredicateObligation < ' tcx > > ,
2144+ ) -> Progress < ' tcx > {
2145+ let ty:: Coroutine ( _, args, _) =
2146+ selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) . kind ( )
2147+ else {
2148+ unreachable ! ( )
2149+ } ;
2150+ let gen_sig = args. as_coroutine ( ) . poly_sig ( ) ;
2151+ let Normalized { value : gen_sig, obligations } = normalize_with_depth (
2152+ selcx,
2153+ obligation. param_env ,
2154+ obligation. cause . clone ( ) ,
2155+ obligation. recursion_depth + 1 ,
2156+ gen_sig,
2157+ ) ;
2158+
2159+ debug ! ( ?obligation, ?gen_sig, ?obligations, "confirm_future_candidate" ) ;
2160+
2161+ let tcx = selcx. tcx ( ) ;
2162+ let iter_def_id = tcx. require_lang_item ( LangItem :: Iterator , None ) ;
2163+
2164+ let predicate = super :: util:: iterator_trait_ref_and_outputs (
2165+ tcx,
2166+ iter_def_id,
2167+ obligation. predicate . self_ty ( ) ,
2168+ gen_sig,
2169+ )
2170+ . map_bound ( |( trait_ref, yield_ty) | {
2171+ debug_assert_eq ! ( tcx. associated_item( obligation. predicate. def_id) . name, sym:: Item ) ;
2172+
2173+ ty:: ProjectionPredicate {
2174+ projection_ty : ty:: AliasTy :: new ( tcx, obligation. predicate . def_id , trait_ref. args ) ,
2175+ term : yield_ty. into ( ) ,
2176+ }
2177+ } ) ;
2178+
2179+ confirm_param_env_candidate ( selcx, obligation, predicate, false )
2180+ . with_addl_obligations ( nested)
2181+ . with_addl_obligations ( obligations)
2182+ }
2183+
21382184fn confirm_builtin_candidate < ' cx , ' tcx > (
21392185 selcx : & mut SelectionContext < ' cx , ' tcx > ,
21402186 obligation : & ProjectionTyObligation < ' tcx > ,
0 commit comments