mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Remove FnPtr hack from trait_ref_is_knowable
This commit is contained in:
parent
b706b9d176
commit
66d7cfd3b5
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,13 +514,6 @@ pub fn trait_ref_is_knowable<'tcx, E: Debug>(
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
mut lazily_normalize_ty: impl FnMut(Ty<'tcx>) -> Result<Ty<'tcx>, 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() {
|
||||
// A downstream or cousin crate is allowed to implement some
|
||||
// substitution of this trait-ref.
|
||||
|
@ -52,8 +52,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
|
||||
let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
|
||||
|
||||
// The only way to prove a NotImplemented(T: Foo) predicate is via a negative impl.
|
||||
// There are no compiler built-in rules for this.
|
||||
// Negative trait predicates have different rules than positive trait predicates.
|
||||
if obligation.polarity() == ty::ImplPolarity::Negative {
|
||||
self.assemble_candidates_for_trait_alias(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>,
|
||||
) {
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
|
||||
|
||||
match self_ty.skip_binder().kind() {
|
||||
ty::FnPtr(_) => candidates.vec.push(BuiltinCandidate { has_nested: false }),
|
||||
ty::Bool
|
||||
|
@ -253,6 +253,7 @@
|
||||
#![feature(try_blocks)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unsized_fn_params)]
|
||||
#![feature(with_negative_coherence)]
|
||||
// tidy-alphabetical-end
|
||||
//
|
||||
// Target features:
|
||||
|
Loading…
Reference in New Issue
Block a user