diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-21 17:57:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-21 17:57:55 -0400 |
| commit | 268ef7bafe340848f9323f27a1b4ac57f32aeda4 (patch) | |
| tree | a78af0e44d46849d7ea0b0db9d81bfeac5e41a5a /compiler/rustc_lint | |
| parent | b426cb2af8b873b21c54e19cd55b43131b732bc7 (diff) | |
| parent | d18d94d8a0416f9013ad6e59ffae3d9e57382add (diff) | |
| download | rust-268ef7bafe340848f9323f27a1b4ac57f32aeda4.tar.gz rust-268ef7bafe340848f9323f27a1b4ac57f32aeda4.zip | |
Rollup merge of #145672 - compiler-errors:query-instab-ice, r=lcnr
Instantiate higher-ranked binder with erased when checking `IntoIterator` predicate for query instability Fixes https://github.com/rust-lang/rust/issues/145652 which was introduced by https://github.com/rust-lang/rust/pull/139345 because we were skipping a binder before calling `Instance::try_resolve`. r? lcnr
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/internal.rs | 23 |
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 |
