1
Fork 0

Remove FnPtr hack from trait_ref_is_knowable

This commit is contained in:
Michael Goulet 2023-05-06 23:43:33 +00:00
parent b706b9d176
commit 66d7cfd3b5
4 changed files with 22 additions and 17 deletions

View file

@ -238,14 +238,25 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> {
if goal.predicate.polarity != ty::ImplPolarity::Positive {
return Err(NoSolution);
}
if let ty::FnPtr(..) = goal.predicate.self_ty().kind() {
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
Err(NoSolution)
let self_ty = goal.predicate.self_ty();
match goal.predicate.polarity {
ty::ImplPolarity::Positive => {
if self_ty.is_fn_ptr() {
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
Err(NoSolution)
}
}
ty::ImplPolarity::Negative => {
// If a type is rigid and not a fn ptr, then we know for certain
// that it does *not* implement `FnPtr`.
if !self_ty.is_fn_ptr() && self_ty.is_known_rigid() {
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
Err(NoSolution)
}
}
ty::ImplPolarity::Reservation => bug!(),
}
}