about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/util/call_kind.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-11-22 02:31:42 +0000
committerMichael Goulet <michael@errs.io>2024-11-22 02:32:26 +0000
commit01ff36a6b9e9134421c4e353ccbc904fdfe53be6 (patch)
tree7965e79810df599931667bcb5465ed14d56b576c /compiler/rustc_middle/src/util/call_kind.rs
parent75703c1a78c3cd99fa1347b237f3966fb8860e98 (diff)
downloadrust-01ff36a6b9e9134421c4e353ccbc904fdfe53be6.tar.gz
rust-01ff36a6b9e9134421c4e353ccbc904fdfe53be6.zip
Get rid of HIR const checker
Diffstat (limited to 'compiler/rustc_middle/src/util/call_kind.rs')
-rw-r--r--compiler/rustc_middle/src/util/call_kind.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/util/call_kind.rs b/compiler/rustc_middle/src/util/call_kind.rs
index acfb78b3f6e..df5b73ac1bd 100644
--- a/compiler/rustc_middle/src/util/call_kind.rs
+++ b/compiler/rustc_middle/src/util/call_kind.rs
@@ -14,6 +14,8 @@ use crate::ty::{AssocItemContainer, GenericArgsRef, Instance, Ty, TyCtxt, Typing
 pub enum CallDesugaringKind {
     /// for _ in x {} calls x.into_iter()
     ForLoopIntoIter,
+    /// for _ in x {} calls iter.next()
+    ForLoopNext,
     /// x? calls x.branch()
     QuestionBranch,
     /// x? calls type_of(x)::from_residual()
@@ -28,6 +30,7 @@ impl CallDesugaringKind {
     pub fn trait_def_id(self, tcx: TyCtxt<'_>) -> DefId {
         match self {
             Self::ForLoopIntoIter => tcx.get_diagnostic_item(sym::IntoIterator).unwrap(),
+            Self::ForLoopNext => tcx.require_lang_item(LangItem::Iterator, None),
             Self::QuestionBranch | Self::TryBlockFromOutput => {
                 tcx.require_lang_item(LangItem::Try, None)
             }
@@ -121,6 +124,10 @@ pub fn call_kind<'tcx>(
             && fn_call_span.desugaring_kind() == Some(DesugaringKind::ForLoop)
         {
             Some((CallDesugaringKind::ForLoopIntoIter, method_args.type_at(0)))
+        } else if tcx.is_lang_item(method_did, LangItem::IteratorNext)
+            && fn_call_span.desugaring_kind() == Some(DesugaringKind::ForLoop)
+        {
+            Some((CallDesugaringKind::ForLoopNext, method_args.type_at(0)))
         } else if fn_call_span.desugaring_kind() == Some(DesugaringKind::QuestionMark) {
             if tcx.is_lang_item(method_did, LangItem::TryTraitBranch) {
                 Some((CallDesugaringKind::QuestionBranch, method_args.type_at(0)))