Add TraitObligation::polarity() for better encapsulation

This commit is contained in:
Santiago Pastorino
2021-10-20 14:12:11 -03:00
parent 7568632513
commit 68d444ffa1
3 changed files with 12 additions and 14 deletions
+4
View File
@@ -140,6 +140,10 @@ pub fn new(
}
impl<'tcx> TraitObligation<'tcx> {
pub fn polarity(&self) -> ty::ImplPolarity {
self.predicate.skip_binder().polarity
}
pub fn self_ty(&self) -> ty::Binder<'tcx, Ty<'tcx>> {
self.predicate.map_bound(|p| p.self_ty())
}
@@ -256,7 +256,7 @@ pub(super) fn assemble_candidates<'o>(
let mut candidates = SelectionCandidateSet { vec: Vec::new(), ambiguous: false };
if obligation.predicate.skip_binder().polarity == ty::ImplPolarity::Negative {
if obligation.polarity() == ty::ImplPolarity::Negative {
self.assemble_candidates_from_impls(obligation, &mut candidates);
} else {
self.assemble_candidates_for_trait_alias(obligation, &mut candidates);
@@ -382,10 +382,7 @@ fn assemble_candidates_from_caller_bounds<'o>(
for bound in matching_bounds {
let wc = self.evaluate_where_clause(stack, bound.value)?;
if wc.may_apply() {
candidates.vec.push(ParamCandidate((
bound,
stack.obligation.predicate.skip_binder().polarity,
)));
candidates.vec.push(ParamCandidate((bound, stack.obligation.polarity())));
}
}
@@ -712,7 +712,7 @@ fn evaluate_trait_predicate_recursively<'o>(
if let Some(result) = self.check_evaluation_cache(
obligation.param_env,
fresh_trait_ref,
obligation.predicate.skip_binder().polarity,
obligation.polarity(),
) {
debug!(?result, "CACHE HIT");
return Ok(result);
@@ -746,7 +746,7 @@ fn evaluate_trait_predicate_recursively<'o>(
self.insert_evaluation_cache(
obligation.param_env,
fresh_trait_ref,
obligation.predicate.skip_binder().polarity,
obligation.polarity(),
dep_node,
result,
);
@@ -755,7 +755,7 @@ fn evaluate_trait_predicate_recursively<'o>(
self.insert_evaluation_cache(
obligation.param_env,
fresh_trait_ref,
obligation.predicate.skip_binder().polarity,
obligation.polarity(),
dep_node,
provisional_result.max(result),
);
@@ -867,7 +867,7 @@ fn evaluate_stack<'o>(
let unbound_input_types =
stack.fresh_trait_ref.value.skip_binder().substs.types().any(|ty| ty.is_fresh());
if stack.obligation.predicate.skip_binder().polarity != ty::ImplPolarity::Negative {
if stack.obligation.polarity() != ty::ImplPolarity::Negative {
// This check was an imperfect workaround for a bug in the old
// intercrate mode; it should be removed when that goes away.
if unbound_input_types && self.intercrate {
@@ -1130,8 +1130,7 @@ fn filter_impls(
if let ImplCandidate(def_id) = candidate {
ty::ImplPolarity::Reservation == tcx.impl_polarity(*def_id)
|| !self.allow_negative_impls
&& stack.obligation.predicate.skip_binder().polarity
== tcx.impl_polarity(*def_id)
&& stack.obligation.polarity() == tcx.impl_polarity(*def_id)
} else {
true
}
@@ -1199,9 +1198,7 @@ fn filter_reservation_impls(
fn is_knowable<'o>(&mut self, stack: &TraitObligationStack<'o, 'tcx>) -> Option<Conflict> {
debug!("is_knowable(intercrate={:?})", self.intercrate);
if !self.intercrate
|| stack.obligation.predicate.skip_binder().polarity == ty::ImplPolarity::Negative
{
if !self.intercrate || stack.obligation.polarity() == ty::ImplPolarity::Negative {
return None;
}