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>, ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
if goal.predicate.polarity != ty::ImplPolarity::Positive { let self_ty = goal.predicate.self_ty();
return Err(NoSolution); match goal.predicate.polarity {
} ty::ImplPolarity::Positive => {
if self_ty.is_fn_ptr() {
if let ty::FnPtr(..) = goal.predicate.self_ty().kind() { ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) } else {
} else { Err(NoSolution)
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!(),
} }
} }

View file

@ -514,13 +514,6 @@ pub fn trait_ref_is_knowable<'tcx, E: Debug>(
trait_ref: ty::TraitRef<'tcx>, trait_ref: ty::TraitRef<'tcx>,
mut lazily_normalize_ty: impl FnMut(Ty<'tcx>) -> Result<Ty<'tcx>, E>, mut lazily_normalize_ty: impl FnMut(Ty<'tcx>) -> Result<Ty<'tcx>, E>,
) -> Result<Result<(), Conflict>, E> { ) -> Result<Result<(), Conflict>, E> {
if Some(trait_ref.def_id) == tcx.lang_items().fn_ptr_trait() {
// The only types implementing `FnPtr` are function pointers,
// so if there's no impl of `FnPtr` in the current crate,
// then such an impl will never be added in the future.
return Ok(Ok(()));
}
if orphan_check_trait_ref(trait_ref, InCrate::Remote, &mut lazily_normalize_ty)?.is_ok() { if orphan_check_trait_ref(trait_ref, InCrate::Remote, &mut lazily_normalize_ty)?.is_ok() {
// A downstream or cousin crate is allowed to implement some // A downstream or cousin crate is allowed to implement some
// substitution of this trait-ref. // substitution of this trait-ref.

View file

@ -52,8 +52,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false }; let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
// The only way to prove a NotImplemented(T: Foo) predicate is via a negative impl. // Negative trait predicates have different rules than positive trait predicates.
// There are no compiler built-in rules for this.
if obligation.polarity() == ty::ImplPolarity::Negative { if obligation.polarity() == ty::ImplPolarity::Negative {
self.assemble_candidates_for_trait_alias(obligation, &mut candidates); self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
self.assemble_candidates_from_impls(obligation, &mut candidates); self.assemble_candidates_from_impls(obligation, &mut candidates);
@ -1064,6 +1063,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates: &mut SelectionCandidateSet<'tcx>, candidates: &mut SelectionCandidateSet<'tcx>,
) { ) {
let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
match self_ty.skip_binder().kind() { match self_ty.skip_binder().kind() {
ty::FnPtr(_) => candidates.vec.push(BuiltinCandidate { has_nested: false }), ty::FnPtr(_) => candidates.vec.push(BuiltinCandidate { has_nested: false }),
ty::Bool ty::Bool

View file

@ -253,6 +253,7 @@
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(unsized_fn_params)] #![feature(unsized_fn_params)]
#![feature(with_negative_coherence)]
// tidy-alphabetical-end // tidy-alphabetical-end
// //
// Target features: // Target features: