From ec03381474f97fce6beb796676b25b9c549b8c9b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 28 Apr 2025 17:01:25 +0000 Subject: [PATCH] Only consider predicate non-global if binder vars are in PREDICATE binder --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 12 +++++++----- .../rustc_trait_selection/src/traits/select/mod.rs | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 2ec14b2f018c3..b8b3e3b5dcd74 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -19,9 +19,8 @@ use rustc_middle::query::Providers; use rustc_middle::traits::solve::NoSolution; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ - self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags, - TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, - Upcast, + self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, + TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_session::parse::feature_err; @@ -2349,8 +2348,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { if let ty::ClauseKind::WellFormed(..) = pred.kind().skip_binder() { continue; } - // Match the existing behavior. - if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) { + // Match the existing behavior and carve out an exception for `for<'a> Ty: Trait`. + if pred.is_global() + && !pred.kind().skip_binder().has_escaping_bound_vars() + && pred.kind().bound_vars().is_empty() + { let pred = self.normalize(span, None, pred); // only use the span of the predicate clause (#90869) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 4ce37db428002..f140a376b350f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1863,7 +1863,9 @@ impl<'tcx> SelectionContext<'_, 'tcx> { // // Our handling of where-bounds is generally fairly messy but necessary for backwards // compatibility, see #50825 for why we need to handle global where-bounds like this. - let is_global = |c: ty::PolyTraitPredicate<'tcx>| c.is_global() && !c.has_bound_vars(); + let is_global = |c: ty::PolyTraitPredicate<'tcx>| { + c.is_global() && !c.skip_binder().has_escaping_bound_vars() + }; let param_candidates = candidates .iter() .filter_map(|c| if let ParamCandidate(p) = c.candidate { Some(p) } else { None });