@@ -1798,7 +1798,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1798
1798
let self_ty = selcx. infcx . shallow_resolve ( obligation. predicate . self_ty ( ) ) ;
1799
1799
1800
1800
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 ) )
1802
1802
|| selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_ref. def_id ) . is_some ( )
1803
1803
{
1804
1804
true
@@ -2015,6 +2015,8 @@ fn confirm_select_candidate<'cx, 'tcx>(
2015
2015
confirm_coroutine_candidate ( selcx, obligation, data)
2016
2016
} else if lang_items. future_trait ( ) == Some ( trait_def_id) {
2017
2017
confirm_future_candidate ( selcx, obligation, data)
2018
+ } else if lang_items. iterator_trait ( ) == Some ( trait_def_id) {
2019
+ confirm_iterator_candidate ( selcx, obligation, data)
2018
2020
} else if selcx. tcx ( ) . fn_trait_kind_from_def_id ( trait_def_id) . is_some ( ) {
2019
2021
if obligation. predicate . self_ty ( ) . is_closure ( ) {
2020
2022
confirm_closure_candidate ( selcx, obligation, data)
@@ -2135,6 +2137,50 @@ fn confirm_future_candidate<'cx, 'tcx>(
2135
2137
. with_addl_obligations ( obligations)
2136
2138
}
2137
2139
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
+
2138
2184
fn confirm_builtin_candidate < ' cx , ' tcx > (
2139
2185
selcx : & mut SelectionContext < ' cx , ' tcx > ,
2140
2186
obligation : & ProjectionTyObligation < ' tcx > ,
0 commit comments