mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-30 14:52:56 +03:00
Un-shadow object bound candidate in NormalizesTo goal
This commit is contained in:
@@ -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() {}
|
||||
Reference in New Issue
Block a user