Skip to content

Commit bd77335

Browse files
authored
Unrolled build for #145672
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 #145652 which was introduced by #139345 because we were skipping a binder before calling `Instance::try_resolve`. r? lcnr
2 parents 6ba0ce4 + d18d94d commit bd77335

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

compiler/rustc_lint/src/internal.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc_hir::def::Res;
55
use rustc_hir::def_id::DefId;
66
use rustc_hir::{Expr, ExprKind, HirId};
7-
use rustc_middle::ty::{self, ClauseKind, GenericArgsRef, PredicatePolarity, TraitPredicate, Ty};
7+
use rustc_middle::ty::{self, GenericArgsRef, PredicatePolarity, Ty};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::hygiene::{ExpnKind, MacroKind};
1010
use rustc_span::{Span, sym};
@@ -129,18 +129,23 @@ fn has_unstable_into_iter_predicate<'tcx>(
129129
};
130130
let predicates = cx.tcx.predicates_of(callee_def_id).instantiate(cx.tcx, generic_args);
131131
for (predicate, _) in predicates {
132-
let ClauseKind::Trait(TraitPredicate { trait_ref, polarity: PredicatePolarity::Positive }) =
133-
predicate.kind().skip_binder()
134-
else {
132+
let Some(trait_pred) = predicate.as_trait_clause() else {
135133
continue;
136134
};
137-
// Does the function or method require any of its arguments to implement `IntoIterator`?
138-
if trait_ref.def_id != into_iterator_def_id {
135+
if trait_pred.def_id() != into_iterator_def_id
136+
|| trait_pred.polarity() != PredicatePolarity::Positive
137+
{
139138
continue;
140139
}
141-
let Ok(Some(instance)) =
142-
ty::Instance::try_resolve(cx.tcx, cx.typing_env(), into_iter_fn_def_id, trait_ref.args)
143-
else {
140+
// `IntoIterator::into_iter` has no additional method args.
141+
let into_iter_fn_args =
142+
cx.tcx.instantiate_bound_regions_with_erased(trait_pred).trait_ref.args;
143+
let Ok(Some(instance)) = ty::Instance::try_resolve(
144+
cx.tcx,
145+
cx.typing_env(),
146+
into_iter_fn_def_id,
147+
into_iter_fn_args,
148+
) else {
144149
continue;
145150
};
146151
// Does the input type's `IntoIterator` implementation have the
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zunstable-options
3+
4+
// Make sure we don't try to resolve instances for trait refs that have escaping
5+
// bound vars when computing the query instability lint.
6+
7+
fn foo<T>() where for<'a> &'a [T]: IntoIterator<Item = &'a T> {}
8+
9+
fn main() {
10+
foo::<()>();
11+
}

0 commit comments

Comments
 (0)