Prefer param-env candidates even when alias's trait bound isn't proven via param-env
This commit is contained in:
parent
2162e9d4b1
commit
2cdb7fac95
1 changed files with 30 additions and 9 deletions
|
@ -791,7 +791,7 @@ where
|
|||
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Ambiguity));
|
||||
};
|
||||
|
||||
let responses: Vec<_> = match proven_via {
|
||||
match proven_via {
|
||||
// Even when a trait bound has been proven using a where-bound, we
|
||||
// still need to consider alias-bounds for normalization, see
|
||||
// tests/ui/next-solver/alias-bound-shadowed-by-env.rs.
|
||||
|
@ -800,7 +800,7 @@ where
|
|||
// constness checking. Doing so is *at least theoretically* breaking,
|
||||
// see github.com/rust-lang/rust/issues/133044#issuecomment-2500709754
|
||||
TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
|
||||
let mut candidates_from_env: Vec<_> = candidates
|
||||
let mut candidates_from_env_and_bounds: Vec<_> = candidates
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
matches!(
|
||||
|
@ -813,16 +813,37 @@ where
|
|||
|
||||
// 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.
|
||||
if candidates_from_env.is_empty() {
|
||||
if candidates_from_env_and_bounds.is_empty() {
|
||||
if let Ok(response) = inject_normalize_to_rigid_candidate(self) {
|
||||
candidates_from_env.push(response);
|
||||
candidates_from_env_and_bounds.push(response);
|
||||
}
|
||||
}
|
||||
candidates_from_env
|
||||
}
|
||||
TraitGoalProvenVia::Misc => candidates.iter().map(|c| c.result).collect(),
|
||||
};
|
||||
|
||||
self.try_merge_responses(&responses).map_or_else(|| self.flounder(&responses), Ok)
|
||||
if let Some(response) = self.try_merge_responses(&candidates_from_env_and_bounds) {
|
||||
Ok(response)
|
||||
} else {
|
||||
self.flounder(&candidates_from_env_and_bounds)
|
||||
}
|
||||
}
|
||||
TraitGoalProvenVia::Misc => {
|
||||
// Prefer "orphaned" param-env normalization predicates, which are used
|
||||
// (for example, and ideally only) when proving item bounds for an impl.
|
||||
let candidates_from_env: Vec<_> = candidates
|
||||
.iter()
|
||||
.filter(|c| matches!(c.source, CandidateSource::ParamEnv(_)))
|
||||
.map(|c| c.result)
|
||||
.collect();
|
||||
if let Some(response) = self.try_merge_responses(&candidates_from_env) {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
let responses: Vec<_> = candidates.iter().map(|c| c.result).collect();
|
||||
if let Some(response) = self.try_merge_responses(&responses) {
|
||||
Ok(response)
|
||||
} else {
|
||||
self.flounder(&responses)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue