about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-08-20 16:49:04 +0000
committerMichael Goulet <michael@errs.io>2025-08-20 16:49:35 +0000
commitd18d94d8a0416f9013ad6e59ffae3d9e57382add (patch)
treee4cfdc6166488c0824427e62848c519ececc1acd /compiler/rustc_lint/src
parente8a792daf500b5ff8097896ddb6cc037abe92487 (diff)
downloadrust-d18d94d8a0416f9013ad6e59ffae3d9e57382add.tar.gz
rust-d18d94d8a0416f9013ad6e59ffae3d9e57382add.zip
Instantiate higher-ranked binder with erased when checking IntoIterator predicate query instability
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/internal.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index e1fbe39222b..929fc8207b0 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -4,7 +4,7 @@
 use rustc_hir::def::Res;
 use rustc_hir::def_id::DefId;
 use rustc_hir::{Expr, ExprKind, HirId};
-use rustc_middle::ty::{self, ClauseKind, GenericArgsRef, PredicatePolarity, TraitPredicate, Ty};
+use rustc_middle::ty::{self, GenericArgsRef, PredicatePolarity, Ty};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::hygiene::{ExpnKind, MacroKind};
 use rustc_span::{Span, sym};
@@ -129,18 +129,23 @@ fn has_unstable_into_iter_predicate<'tcx>(
     };
     let predicates = cx.tcx.predicates_of(callee_def_id).instantiate(cx.tcx, generic_args);
     for (predicate, _) in predicates {
-        let ClauseKind::Trait(TraitPredicate { trait_ref, polarity: PredicatePolarity::Positive }) =
-            predicate.kind().skip_binder()
-        else {
+        let Some(trait_pred) = predicate.as_trait_clause() else {
             continue;
         };
-        // Does the function or method require any of its arguments to implement `IntoIterator`?
-        if trait_ref.def_id != into_iterator_def_id {
+        if trait_pred.def_id() != into_iterator_def_id
+            || trait_pred.polarity() != PredicatePolarity::Positive
+        {
             continue;
         }
-        let Ok(Some(instance)) =
-            ty::Instance::try_resolve(cx.tcx, cx.typing_env(), into_iter_fn_def_id, trait_ref.args)
-        else {
+        // `IntoIterator::into_iter` has no additional method args.
+        let into_iter_fn_args =
+            cx.tcx.instantiate_bound_regions_with_erased(trait_pred).trait_ref.args;
+        let Ok(Some(instance)) = ty::Instance::try_resolve(
+            cx.tcx,
+            cx.typing_env(),
+            into_iter_fn_def_id,
+            into_iter_fn_args,
+        ) else {
             continue;
         };
         // Does the input type's `IntoIterator` implementation have the