mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Take the polarity into account in compute_applicable_impls
This commit is contained in:
parent
96eaf553e5
commit
524f3c9c44
@ -19,6 +19,8 @@ pub fn recompute_applicable_impls<'tcx>(
|
||||
let tcx = infcx.tcx;
|
||||
let param_env = obligation.param_env;
|
||||
|
||||
let predicate_polarity = obligation.predicate.skip_binder().polarity;
|
||||
|
||||
let impl_may_apply = |impl_def_id| {
|
||||
let ocx = ObligationCtxt::new(infcx);
|
||||
infcx.enter_forall(obligation.predicate, |placeholder_obligation| {
|
||||
@ -40,6 +42,15 @@ pub fn recompute_applicable_impls<'tcx>(
|
||||
return false;
|
||||
}
|
||||
|
||||
let impl_trait_header = tcx.impl_trait_header(impl_def_id).unwrap();
|
||||
let impl_polarity = impl_trait_header.polarity;
|
||||
|
||||
match (impl_polarity, predicate_polarity) {
|
||||
(ty::ImplPolarity::Positive, ty::PredicatePolarity::Positive)
|
||||
| (ty::ImplPolarity::Negative, ty::PredicatePolarity::Negative) => {}
|
||||
_ => return false,
|
||||
}
|
||||
|
||||
let impl_predicates = tcx.predicates_of(impl_def_id).instantiate(tcx, impl_args);
|
||||
ocx.register_obligations(impl_predicates.predicates.iter().map(|&predicate| {
|
||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate)
|
||||
|
Loading…
Reference in New Issue
Block a user