Un-shadow object bound candidate in NormalizesTo goal

This commit is contained in:
Adwin White
2025-10-30 20:22:45 +08:00
parent ab1d244453
commit 2fbb751985
2 changed files with 23 additions and 0 deletions
@@ -1143,6 +1143,12 @@ pub(super) fn assemble_and_merge_candidates<G: GoalKind<D>>(
// See `tests/ui/winnowing/norm-where-bound-gt-alias-bound.rs`.
if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) {
candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_)));
} else if matches!(goal.predicate.self_ty().kind(), ty::Dynamic(..)) {
// Object candidate may be shadowed by where-bound for the trait goal, see
// `tests/ui/traits/next-solver/normalization-shadowing/use_object_if_empty_env.rs`.
// Trait objects always have their associated types specified so `candidates`
// won't be empty.
self.assemble_object_bound_candidates(goal, &mut candidates);
} else if candidates.is_empty() {
// If the trait goal has been proven by using the environment, we want to treat
// aliases as rigid if there are no applicable projection bounds in the environment.
@@ -0,0 +1,17 @@
//@ compile-flags: -Znext-solver
//@ check-pass
trait Trait {
type Assoc;
}
// We have param env candidate for the trait goal but not the projection.
// Under such circumstance, consider object candidate if the self_ty is trait object.
fn foo<T>(x: <dyn Trait<Assoc = T> as Trait>::Assoc) -> T
where
dyn Trait<Assoc = T>: Trait,
{
x
}
fn main() {}