Skip to content

Commit ec03381

Browse files
Only consider predicate non-global if binder vars are in PREDICATE binder
1 parent c4e05e5 commit ec03381

File tree

2 files changed

+10
-6
lines changed
  • compiler
    • rustc_hir_analysis/src/check
    • rustc_trait_selection/src/traits/select

2 files changed

+10
-6
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use rustc_middle::query::Providers;
1919
use rustc_middle::traits::solve::NoSolution;
2020
use rustc_middle::ty::trait_def::TraitSpecializationKind;
2121
use rustc_middle::ty::{
22-
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags,
23-
TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
24-
Upcast,
22+
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
23+
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
2524
};
2625
use rustc_middle::{bug, span_bug};
2726
use rustc_session::parse::feature_err;
@@ -2349,8 +2348,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
23492348
if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() {
23502349
continue;
23512350
}
2352-
// Match the existing behavior.
2353-
if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) {
2351+
// Match the existing behavior and carve out an exception for `for<'a> Ty: Trait`.
2352+
if pred.is_global()
2353+
&& !pred.kind().skip_binder().has_escaping_bound_vars()
2354+
&& pred.kind().bound_vars().is_empty()
2355+
{
23542356
let pred = self.normalize(span, None, pred);
23552357

23562358
// only use the span of the predicate clause (#90869)

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,9 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18631863
//
18641864
// Our handling of where-bounds is generally fairly messy but necessary for backwards
18651865
// compatibility, see #50825 for why we need to handle global where-bounds like this.
1866-
let is_global = |c: ty::PolyTraitPredicate<'tcx>| c.is_global() && !c.has_bound_vars();
1866+
let is_global = |c: ty::PolyTraitPredicate<'tcx>| {
1867+
c.is_global() && !c.skip_binder().has_escaping_bound_vars()
1868+
};
18671869
let param_candidates = candidates
18681870
.iter()
18691871
.filter_map(|c| if let ParamCandidate(p) = c.candidate { Some(p) } else { None });

0 commit comments

Comments
 (0)