about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2021-10-20 14:12:11 -0300
committerSantiago Pastorino <spastorino@gmail.com>2021-10-20 14:45:10 -0300
commit68d444ffa19fa5feda8550a4a8d4dfb2f1da04b6 (patch)
tree041843dd4be173f0e9a484a805ebe01150810dce
parent7568632513c4f9e4324e0d7cf97df791c0df4333 (diff)
downloadrust-68d444ffa19fa5feda8550a4a8d4dfb2f1da04b6.tar.gz
rust-68d444ffa19fa5feda8550a4a8d4dfb2f1da04b6.zip
Add TraitObligation::polarity() for better encapsulation
-rw-r--r--compiler/rustc_infer/src/traits/mod.rs4
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs7
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs15
3 files changed, 12 insertions, 14 deletions
diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs
index 8b99db06891..033d634cdb7 100644
--- a/compiler/rustc_infer/src/traits/mod.rs
+++ b/compiler/rustc_infer/src/traits/mod.rs
@@ -140,6 +140,10 @@ impl<'tcx> FulfillmentError<'tcx> {
 }
 
 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())
     }
diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
index 0c1c2340c71..8bb7ed8de23 100644
--- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
@@ -256,7 +256,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
 
         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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         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())));
             }
         }
 
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 2748dfcca6c..77763188054 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -712,7 +712,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             self.insert_evaluation_cache(
                 obligation.param_env,
                 fresh_trait_ref,
-                obligation.predicate.skip_binder().polarity,
+                obligation.polarity(),
                 dep_node,
                 result,
             );
@@ -755,7 +755,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
                 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
     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;
         }