@@ -1789,7 +1789,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
17891789 let self_ty = selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) ;
17901790
17911791 let lang_items = selcx. tcx ( ) . lang_items ( ) ;
1792- if [ lang_items. gen_trait ( ) , lang_items. future_trait ( ) ] . contains ( & Some ( trait_ref. def_id ) )
1792+ if [ lang_items. gen_trait ( ) , lang_items. future_trait ( ) , lang_items . iterator_trait ( ) ] . contains ( & Some ( trait_ref. def_id ) )
17931793 || selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_ref. def_id ) . is_some ( )
17941794 {
17951795 true
@@ -2006,6 +2006,8 @@ fn confirm_select_candidate<'cx, 'tcx>(
20062006 confirm_coroutine_candidate ( selcx, obligation, data)
20072007 } else if lang_items. future_trait ( ) == Some ( trait_def_id) {
20082008 confirm_future_candidate ( selcx, obligation, data)
2009+ } else if lang_items. iterator_trait ( ) == Some ( trait_def_id) {
2010+ confirm_iterator_candidate ( selcx, obligation, data)
20092011 } else if selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_def_id) . is_some ( ) {
20102012 if obligation. predicate . self_ty ( ) . is_closure ( ) {
20112013 confirm_closure_candidate ( selcx, obligation, data)
@@ -2126,6 +2128,50 @@ fn confirm_future_candidate<'cx, 'tcx>(
21262128 . with_addl_obligations ( obligations)
21272129}
21282130
2131+ fn confirm_iterator_candidate < ' cx , ' tcx > (
2132+ selcx : & mut SelectionContext < ' cx , ' tcx > ,
2133+ obligation : & ProjectionTyObligation < ' tcx > ,
2134+ nested : Vec < PredicateObligation < ' tcx > > ,
2135+ ) -> Progress < ' tcx > {
2136+ let ty:: Coroutine ( _, args, _) =
2137+ selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) . kind ( )
2138+ else {
2139+ unreachable ! ( )
2140+ } ;
2141+ let gen_sig = args. as_coroutine ( ) . poly_sig ( ) ;
2142+ let Normalized { value : gen_sig, obligations } = normalize_with_depth (
2143+ selcx,
2144+ obligation. param_env ,
2145+ obligation. cause . clone ( ) ,
2146+ obligation. recursion_depth + 1 ,
2147+ gen_sig,
2148+ ) ;
2149+
2150+ debug ! ( ?obligation, ?gen_sig, ?obligations, "confirm_future_candidate" ) ;
2151+
2152+ let tcx = selcx. tcx ( ) ;
2153+ let iter_def_id = tcx. require_lang_item ( LangItem :: Iterator , None ) ;
2154+
2155+ let predicate = super :: util:: iterator_trait_ref_and_outputs (
2156+ tcx,
2157+ iter_def_id,
2158+ obligation. predicate . self_ty ( ) ,
2159+ gen_sig,
2160+ )
2161+ . map_bound ( |( trait_ref, yield_ty) | {
2162+ debug_assert_eq ! ( tcx. associated_item( obligation. predicate. def_id) . name, sym:: Item ) ;
2163+
2164+ ty:: ProjectionPredicate {
2165+ projection_ty : ty:: AliasTy :: new ( tcx, obligation. predicate . def_id , trait_ref. args ) ,
2166+ term : yield_ty. into ( ) ,
2167+ }
2168+ } ) ;
2169+
2170+ confirm_param_env_candidate ( selcx, obligation, predicate, false )
2171+ . with_addl_obligations ( nested)
2172+ . with_addl_obligations ( obligations)
2173+ }
2174+
21292175fn confirm_builtin_candidate < ' cx , ' tcx > (
21302176 selcx : & mut SelectionContext < ' cx , ' tcx > ,
21312177 obligation : & ProjectionTyObligation < ' tcx > ,
0 commit comments