@@ -1789,7 +1789,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1789
1789
let self_ty = selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) ;
1790
1790
1791
1791
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 ) )
1793
1793
|| selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_ref. def_id ) . is_some ( )
1794
1794
{
1795
1795
true
@@ -2006,6 +2006,8 @@ fn confirm_select_candidate<'cx, 'tcx>(
2006
2006
confirm_coroutine_candidate ( selcx, obligation, data)
2007
2007
} else if lang_items. future_trait ( ) == Some ( trait_def_id) {
2008
2008
confirm_future_candidate ( selcx, obligation, data)
2009
+ } else if lang_items. iterator_trait ( ) == Some ( trait_def_id) {
2010
+ confirm_iterator_candidate ( selcx, obligation, data)
2009
2011
} else if selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_def_id) . is_some ( ) {
2010
2012
if obligation. predicate . self_ty ( ) . is_closure ( ) {
2011
2013
confirm_closure_candidate ( selcx, obligation, data)
@@ -2126,6 +2128,50 @@ fn confirm_future_candidate<'cx, 'tcx>(
2126
2128
. with_addl_obligations ( obligations)
2127
2129
}
2128
2130
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
+
2129
2175
fn confirm_builtin_candidate < ' cx , ' tcx > (
2130
2176
selcx : & mut SelectionContext < ' cx , ' tcx > ,
2131
2177
obligation : & ProjectionTyObligation < ' tcx > ,
0 commit comments