]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_middle/ty/flags.rs
introduce PredicateAtom
[rust.git] / src / librustc_middle / ty / flags.rs
index 11a8bedb6605bf6caa3de7fd23e818806f244f72..7452089658feba4afb3016a275398835e97bfe0f 100644 (file)
@@ -201,60 +201,55 @@ fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
         }
     }
 
+    fn add_predicate(&mut self, pred: ty::Predicate<'_>) {
+        self.add_flags(pred.inner.flags);
+        self.add_exclusive_binder(pred.inner.outer_exclusive_binder);
+    }
+
     fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
         match kind {
-            ty::PredicateKind::Trait(trait_pred, _constness) => {
-                let mut computation = FlagComputation::new();
-                computation.add_substs(trait_pred.skip_binder().trait_ref.substs);
-
-                self.add_bound_computation(computation);
-            }
-            ty::PredicateKind::RegionOutlives(poly_outlives) => {
-                let mut computation = FlagComputation::new();
-                let ty::OutlivesPredicate(a, b) = poly_outlives.skip_binder();
-                computation.add_region(a);
-                computation.add_region(b);
-
-                self.add_bound_computation(computation);
-            }
-            ty::PredicateKind::TypeOutlives(poly_outlives) => {
-                let mut computation = FlagComputation::new();
-                let ty::OutlivesPredicate(ty, region) = poly_outlives.skip_binder();
-                computation.add_ty(ty);
-                computation.add_region(region);
-
-                self.add_bound_computation(computation);
-            }
-            ty::PredicateKind::Subtype(poly_subtype) => {
+            ty::PredicateKind::ForAll(binder) => {
                 let mut computation = FlagComputation::new();
-                let ty::SubtypePredicate { a_is_expected: _, a, b } = poly_subtype.skip_binder();
-                computation.add_ty(a);
-                computation.add_ty(b);
 
-                self.add_bound_computation(computation);
-            }
-            &ty::PredicateKind::Projection(projection) => {
-                let mut computation = FlagComputation::new();
-                let ty::ProjectionPredicate { projection_ty, ty } = projection.skip_binder();
-                computation.add_projection_ty(projection_ty);
-                computation.add_ty(ty);
+                computation.add_predicate(binder.skip_binder());
 
                 self.add_bound_computation(computation);
             }
-            ty::PredicateKind::WellFormed(arg) => {
-                self.add_substs(slice::from_ref(arg));
-            }
-            ty::PredicateKind::ObjectSafe(_def_id) => {}
-            ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
-                self.add_substs(substs);
-            }
-            ty::PredicateKind::ConstEvaluatable(_def_id, substs) => {
-                self.add_substs(substs);
-            }
-            ty::PredicateKind::ConstEquate(expected, found) => {
-                self.add_const(expected);
-                self.add_const(found);
-            }
+            &ty::PredicateKind::Atom(atom) => match atom {
+                ty::PredicateAtom::Trait(trait_pred, _constness) => {
+                    self.add_substs(trait_pred.trait_ref.substs);
+                }
+                ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
+                    self.add_region(a);
+                    self.add_region(b);
+                }
+                ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
+                    self.add_ty(ty);
+                    self.add_region(region);
+                }
+                ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
+                    self.add_ty(a);
+                    self.add_ty(b);
+                }
+                ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
+                    self.add_projection_ty(projection_ty);
+                    self.add_ty(ty);
+                }
+                ty::PredicateAtom::WellFormed(arg) => {
+                    self.add_substs(slice::from_ref(&arg));
+                }
+                ty::PredicateAtom::ObjectSafe(_def_id) => {}
+                ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => {
+                    self.add_substs(substs);
+                }
+                ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => {
+                    self.add_substs(substs);
+                }
+                ty::PredicateAtom::ConstEquate(expected, found) => {
+                    self.add_const(expected);
+                    self.add_const(found);
+                }
+            },
         }
     }