@@ -14,6 +14,8 @@ use crate::ty::{AssocItemContainer, GenericArgsRef, Instance, Ty, TyCtxt, Typing
1414pub enum CallDesugaringKind {
1515 /// for _ in x {} calls x.into_iter()
1616 ForLoopIntoIter ,
17+ /// for _ in x {} calls iter.next()
18+ ForLoopNext ,
1719 /// x? calls x.branch()
1820 QuestionBranch ,
1921 /// x? calls type_of(x)::from_residual()
@@ -28,6 +30,7 @@ impl CallDesugaringKind {
2830 pub fn trait_def_id ( self , tcx : TyCtxt < ' _ > ) -> DefId {
2931 match self {
3032 Self :: ForLoopIntoIter => tcx. get_diagnostic_item ( sym:: IntoIterator ) . unwrap ( ) ,
33+ Self :: ForLoopNext => tcx. require_lang_item ( LangItem :: Iterator , None ) ,
3134 Self :: QuestionBranch | Self :: TryBlockFromOutput => {
3235 tcx. require_lang_item ( LangItem :: Try , None )
3336 }
@@ -121,6 +124,10 @@ pub fn call_kind<'tcx>(
121124 && fn_call_span. desugaring_kind ( ) == Some ( DesugaringKind :: ForLoop )
122125 {
123126 Some ( ( CallDesugaringKind :: ForLoopIntoIter , method_args. type_at ( 0 ) ) )
127+ } else if tcx. is_lang_item ( method_did, LangItem :: IteratorNext )
128+ && fn_call_span. desugaring_kind ( ) == Some ( DesugaringKind :: ForLoop )
129+ {
130+ Some ( ( CallDesugaringKind :: ForLoopNext , method_args. type_at ( 0 ) ) )
124131 } else if fn_call_span. desugaring_kind ( ) == Some ( DesugaringKind :: QuestionMark ) {
125132 if tcx. is_lang_item ( method_did, LangItem :: TryTraitBranch ) {
126133 Some ( ( CallDesugaringKind :: QuestionBranch , method_args. type_at ( 0 ) ) )
0 commit comments