]> git.lizzy.rs Git - rust.git/commitdiff
introduce PredicateAtom
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Wed, 8 Jul 2020 22:35:55 +0000 (00:35 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Mon, 27 Jul 2020 19:07:37 +0000 (21:07 +0200)
54 files changed:
src/librustc_infer/infer/canonical/query_response.rs
src/librustc_infer/infer/combine.rs
src/librustc_infer/infer/outlives/mod.rs
src/librustc_infer/infer/sub.rs
src/librustc_infer/traits/util.rs
src/librustc_lint/builtin.rs
src/librustc_lint/unused.rs
src/librustc_middle/ty/flags.rs
src/librustc_middle/ty/mod.rs
src/librustc_middle/ty/print/pretty.rs
src/librustc_middle/ty/structural_impls.rs
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
src/librustc_mir/borrow_check/type_check/mod.rs
src/librustc_mir/transform/qualify_min_const_fn.rs
src/librustc_privacy/lib.rs
src/librustc_trait_selection/opaque_types.rs
src/librustc_trait_selection/traits/auto_trait.rs
src/librustc_trait_selection/traits/error_reporting/mod.rs
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
src/librustc_trait_selection/traits/fulfill.rs
src/librustc_trait_selection/traits/mod.rs
src/librustc_trait_selection/traits/object_safety.rs
src/librustc_trait_selection/traits/project.rs
src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs
src/librustc_trait_selection/traits/select/confirmation.rs
src/librustc_trait_selection/traits/select/mod.rs
src/librustc_trait_selection/traits/wf.rs
src/librustc_traits/chalk/lowering.rs
src/librustc_traits/implied_outlives_bounds.rs
src/librustc_traits/normalize_erasing_regions.rs
src/librustc_traits/type_op.rs
src/librustc_ty/ty.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/dropck.rs
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/method/suggest.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/constrained_generic_params.rs
src/librustc_typeck/impl_wf_check/min_specialization.rs
src/librustc_typeck/outlives/explicit.rs
src/librustc_typeck/outlives/mod.rs
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/mod.rs
src/librustdoc/clean/simplify.rs
src/tools/clippy/clippy_lints/src/future_not_send.rs
src/tools/clippy/clippy_lints/src/methods/mod.rs
src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs
src/tools/clippy/clippy_lints/src/utils/mod.rs

index a6229e61ae77ddab02c8c8260696955fb41ca461..8406eb9bc175bd7519e8f55d7e6762ebbfb4a6c3 100644 (file)
@@ -530,11 +530,11 @@ fn query_outlives_constraints_into_obligations<'a>(
 
             let predicate = match k1.unpack() {
                 GenericArgKind::Lifetime(r1) => {
-                    ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
+                    ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
                         .to_predicate(self.tcx)
                 }
                 GenericArgKind::Type(t1) => {
-                    ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2))
+                    ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2))
                         .to_predicate(self.tcx)
                 }
                 GenericArgKind::Const(..) => {
@@ -665,7 +665,7 @@ fn push_outlives(&mut self, sup: ty::Region<'tcx>, sub: ty::Region<'tcx>) {
         self.obligations.push(Obligation {
             cause: self.cause.clone(),
             param_env: self.param_env,
-            predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
+            predicate: ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(sup, sub))
                 .to_predicate(self.infcx.tcx),
             recursion_depth: 0,
         });
index c63464e5baec9e3b1a71409ad0402cc1a710684e..5b4d91de3ca92afd3edb38cdb141fbd49338786a 100644 (file)
@@ -308,7 +308,7 @@ pub fn instantiate(
             self.obligations.push(Obligation::new(
                 self.trace.cause.clone(),
                 self.param_env,
-                ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
+                ty::PredicateAtom::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
             ));
         }
 
@@ -400,9 +400,9 @@ pub fn add_const_equate_obligation(
         b: &'tcx ty::Const<'tcx>,
     ) {
         let predicate = if a_is_expected {
-            ty::PredicateKind::ConstEquate(a, b)
+            ty::PredicateAtom::ConstEquate(a, b)
         } else {
-            ty::PredicateKind::ConstEquate(b, a)
+            ty::PredicateAtom::ConstEquate(b, a)
         };
         self.obligations.push(Obligation::new(
             self.trace.cause.clone(),
index 541a2f18045c4a5b9a24356f09c27b62f027be7e..6009d4e65793b06dfbcc25b2c72b13745e51b2a1 100644 (file)
@@ -6,23 +6,29 @@
 
 use rustc_middle::traits::query::OutlivesBound;
 use rustc_middle::ty;
+use rustc_middle::ty::fold::TypeFoldable;
 
 pub fn explicit_outlives_bounds<'tcx>(
     param_env: ty::ParamEnv<'tcx>,
 ) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
     debug!("explicit_outlives_bounds()");
-    param_env.caller_bounds().into_iter().filter_map(move |predicate| match predicate.kind() {
-        ty::PredicateKind::Projection(..)
-        | ty::PredicateKind::Trait(..)
-        | ty::PredicateKind::Subtype(..)
-        | ty::PredicateKind::WellFormed(..)
-        | ty::PredicateKind::ObjectSafe(..)
-        | ty::PredicateKind::ClosureKind(..)
-        | ty::PredicateKind::TypeOutlives(..)
-        | ty::PredicateKind::ConstEvaluatable(..)
-        | ty::PredicateKind::ConstEquate(..) => None,
-        ty::PredicateKind::RegionOutlives(ref data) => data
-            .no_bound_vars()
-            .map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
-    })
+    param_env
+        .caller_bounds()
+        .into_iter()
+        .map(ty::Predicate::skip_binders)
+        .filter(TypeFoldable::has_escaping_bound_vars)
+        .filter_map(move |atom| match atom {
+            ty::PredicateAtom::Projection(..)
+            | ty::PredicateAtom::Trait(..)
+            | ty::PredicateAtom::Subtype(..)
+            | ty::PredicateAtom::WellFormed(..)
+            | ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::TypeOutlives(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => None,
+            ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
+                Some(OutlivesBound::RegionSubRegion(r_b, r_a))
+            }
+        })
 }
index 5ad08f0b8952abc867e304f210e64dad5a3c49ce..4f860c77d6541c068e31aface4ae6da3e056761b 100644 (file)
@@ -100,7 +100,7 @@ fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
                 self.fields.obligations.push(Obligation::new(
                     self.fields.trace.cause.clone(),
                     self.fields.param_env,
-                    ty::PredicateKind::Subtype(ty::SubtypePredicate {
+                    ty::PredicateAtom::Subtype(ty::SubtypePredicate {
                         a_is_expected: self.a_is_expected,
                         a,
                         b,
index 0d343be2c264fca3e4c18bf2bdfba0381f43dbe1..93fc7f1f3b8a7e97b49ff7f4b3f35afda7a953a4 100644 (file)
@@ -15,16 +15,7 @@ pub fn anonymize_predicate<'tcx>(
             let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
             tcx.reuse_or_mk_predicate(pred, new)
         }
-        ty::PredicateKind::Trait(_, _)
-        | ty::PredicateKind::RegionOutlives(_)
-        | ty::PredicateKind::TypeOutlives(_)
-        | ty::PredicateKind::Projection(_)
-        | ty::PredicateKind::WellFormed(_)
-        | ty::PredicateKind::ObjectSafe(_)
-        | ty::PredicateKind::ClosureKind(_, _, _)
-        | ty::PredicateKind::Subtype(_)
-        | ty::PredicateKind::ConstEvaluatable(_, _)
-        | ty::PredicateKind::ConstEquate(_, _) => pred,
+        ty::PredicateKind::Atom(_) => pred,
     }
 }
 
@@ -137,11 +128,8 @@ pub fn filter_to_traits(self) -> FilterToTraits<Self> {
     fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
         let tcx = self.visited.tcx;
 
-        match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::ForAll(_) => {
-                bug!("unexpected predicate: {:?}", obligation.predicate)
-            }
-            ty::PredicateKind::Trait(data, _) => {
+        match obligation.predicate.skip_binders() {
+            ty::PredicateAtom::Trait(data, _) => {
                 // Get predicates declared on the trait.
                 let predicates = tcx.super_predicates_of(data.def_id());
 
@@ -162,36 +150,36 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
 
                 self.stack.extend(obligations);
             }
-            ty::PredicateKind::WellFormed(..) => {
+            ty::PredicateAtom::WellFormed(..) => {
                 // Currently, we do not elaborate WF predicates,
                 // although we easily could.
             }
-            ty::PredicateKind::ObjectSafe(..) => {
+            ty::PredicateAtom::ObjectSafe(..) => {
                 // Currently, we do not elaborate object-safe
                 // predicates.
             }
-            ty::PredicateKind::Subtype(..) => {
+            ty::PredicateAtom::Subtype(..) => {
                 // Currently, we do not "elaborate" predicates like `X <: Y`,
                 // though conceivably we might.
             }
-            ty::PredicateKind::Projection(..) => {
+            ty::PredicateAtom::Projection(..) => {
                 // Nothing to elaborate in a projection predicate.
             }
-            ty::PredicateKind::ClosureKind(..) => {
+            ty::PredicateAtom::ClosureKind(..) => {
                 // Nothing to elaborate when waiting for a closure's kind to be inferred.
             }
-            ty::PredicateKind::ConstEvaluatable(..) => {
+            ty::PredicateAtom::ConstEvaluatable(..) => {
                 // Currently, we do not elaborate const-evaluatable
                 // predicates.
             }
-            ty::PredicateKind::ConstEquate(..) => {
+            ty::PredicateAtom::ConstEquate(..) => {
                 // Currently, we do not elaborate const-equate
                 // predicates.
             }
-            ty::PredicateKind::RegionOutlives(..) => {
+            ty::PredicateAtom::RegionOutlives(..) => {
                 // Nothing to elaborate from `'a: 'b`.
             }
-            ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
+            ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => {
                 // We know that `T: 'a` for some type `T`. We can
                 // often elaborate this. For example, if we know that
                 // `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -221,7 +209,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
                                 if r.is_late_bound() {
                                     None
                                 } else {
-                                    Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
+                                    Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
                                         r, r_min,
                                     )))
                                 }
@@ -229,7 +217,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
 
                             Component::Param(p) => {
                                 let ty = tcx.mk_ty_param(p.index, p.name);
-                                Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
+                                Some(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
                                     ty, r_min,
                                 )))
                             }
index 00d532c7ba0babd3c5c5bf9b8ee419f3e96ba153..d67be44e4f0c5d97d3ca7abd2af8ef99ba63baec 100644 (file)
@@ -1202,7 +1202,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
 impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
     fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
         use rustc_middle::ty::fold::TypeFoldable;
-        use rustc_middle::ty::PredicateKind::*;
+        use rustc_middle::ty::PredicateAtom::*;
 
         if cx.tcx.features().trivial_bounds {
             let def_id = cx.tcx.hir().local_def_id(item.hir_id);
@@ -1210,7 +1210,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
             for &(predicate, span) in predicates.predicates {
                 // We don't actually look inside of the predicate,
                 // so it is safe to skip this binder here.
-                let predicate_kind_name = match predicate.ignore_quantifiers().skip_binder().kind() {
+                let predicate_kind_name = match predicate.skip_binders() {
                     Trait(..) => "Trait",
                     TypeOutlives(..) |
                     RegionOutlives(..) => "Lifetime",
@@ -1225,7 +1225,6 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
                     Subtype(..) |
                     ConstEvaluatable(..) |
                     ConstEquate(..) => continue,
-                    ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
                 };
                 if predicate.is_global() {
                     cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {
@@ -1500,8 +1499,8 @@ fn lifetimes_outliving_lifetime<'tcx>(
     ) -> Vec<ty::Region<'tcx>> {
         inferred_outlives
             .iter()
-            .filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
-                &ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
+            .filter_map(|(pred, _)| match pred.skip_binders() {
+                ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a {
                     ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
                     _ => None,
                 },
@@ -1516,8 +1515,8 @@ fn lifetimes_outliving_type<'tcx>(
     ) -> Vec<ty::Region<'tcx>> {
         inferred_outlives
             .iter()
-            .filter_map(|(pred, _)| match pred.ignore_quantifiers().skip_binder().kind() {
-                &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
+            .filter_map(|(pred, _)| match pred.skip_binders() {
+                ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
                     a.is_param(index).then_some(b)
                 }
                 _ => None,
index 8f21cb51695a2f7de451af6e5204ca7e8874566b..dcb44ab64449840b526466a7771040bebba06922 100644 (file)
@@ -147,8 +147,8 @@ fn check_must_use_ty<'tcx>(
                     let mut has_emitted = false;
                     for (predicate, _) in cx.tcx.predicates_of(def).predicates {
                         // We only look at the `DefId`, so it is safe to skip the binder here.
-                        if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
-                            predicate.ignore_quantifiers().skip_binder().kind()
+                        if let ty::PredicateAtom::Trait(ref poly_trait_predicate, _) =
+                            predicate.skip_binders()
                         {
                             let def_id = poly_trait_predicate.trait_ref.def_id;
                             let descr_pre =
index 4b1f970edb09c8de16e4b1e929fb88b81985988d..7452089658feba4afb3016a275398835e97bfe0f 100644 (file)
@@ -208,39 +208,6 @@ fn add_predicate(&mut self, pred: ty::Predicate<'_>) {
 
     fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
         match kind {
-            ty::PredicateKind::Trait(trait_pred, _constness) => {
-                self.add_substs(trait_pred.trait_ref.substs);
-            }
-            ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
-                self.add_region(a);
-                self.add_region(b);
-            }
-            ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => {
-                self.add_ty(ty);
-                self.add_region(region);
-            }
-            ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
-                self.add_ty(a);
-                self.add_ty(b);
-            }
-            &ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
-                self.add_projection_ty(projection_ty);
-                self.add_ty(ty);
-            }
-            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::ForAll(binder) => {
                 let mut computation = FlagComputation::new();
 
@@ -248,6 +215,41 @@ fn add_predicate_kind(&mut self, kind: &ty::PredicateKind<'_>) {
 
                 self.add_bound_computation(computation);
             }
+            &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);
+                }
+            },
         }
     }
 
index c8ad8ae10dc35b3e3b910d413f56c1b66e5b7958..0ff475fb288a6fa24c75e10d2dca11ffd7fff41a 100644 (file)
@@ -1018,7 +1018,7 @@ pub fn instantiate_supertrait(
 }
 
 #[cfg(target_arch = "x86_64")]
-static_assert_size!(PredicateInner<'_>, 40);
+static_assert_size!(PredicateInner<'_>, 48);
 
 #[derive(Clone, Copy, Lift)]
 pub struct Predicate<'tcx> {
@@ -1049,46 +1049,35 @@ pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
         &self.inner.kind
     }
 
-    /// Skips `PredicateKind::ForAll`.
-    pub fn ignore_quantifiers(self) -> Binder<Predicate<'tcx>> {
+    /// Returns the inner `PredicateAtom`.
+    ///
+    /// Note that this method panics in case this predicate has unbound variables.
+    pub fn skip_binders(self) -> PredicateAtom<'tcx> {
         match self.kind() {
-            &PredicateKind::ForAll(binder) => binder,
-            ty::PredicateKind::Projection(..)
-            | ty::PredicateKind::Trait(..)
-            | ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::TypeOutlives(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..)
-            | ty::PredicateKind::RegionOutlives(..) => Binder::dummy(self),
+            &PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
+            &ty::PredicateKind::Atom(atom) => atom,
         }
     }
 
-    /// Skips `PredicateKind::ForAll`, while allowing for unbound variables.
-    ///
-    /// This method requires the `TyCtxt` as it has to shift the unbound variables
-    /// outwards.
+    /// Returns the inner `PredicateAtom`.
     ///
-    /// Do not use this method if you may end up just skipping the binder, as this
-    /// would leave the unbound variables at an incorrect binding level.
-    pub fn ignore_quantifiers_with_unbound_vars(
-        self,
-        tcx: TyCtxt<'tcx>,
-    ) -> Binder<Predicate<'tcx>> {
+    /// Note that this method does not check if predicate has unbound variables,
+    /// rebinding the returned atom potentially causes the previously bound variables
+    /// to end up at the wrong binding level.
+    pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
+        match self.kind() {
+            &PredicateKind::ForAll(binder) => binder.skip_binder().skip_binders(),
+            &ty::PredicateKind::Atom(atom) => atom,
+        }
+    }
+
+    pub fn bound_atom(self, tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
         match self.kind() {
-            &PredicateKind::ForAll(binder) => binder,
-            ty::PredicateKind::Projection(..)
-            | ty::PredicateKind::Trait(..)
-            | ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::TypeOutlives(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..)
-            | ty::PredicateKind::RegionOutlives(..) => Binder::wrap_nonbinding(tcx, self),
+            &PredicateKind::ForAll(binder) => binder.map_bound(|inner| match inner.kind() {
+                ty::PredicateKind::ForAll(_) => bug!("unexpect forall"),
+                &ty::PredicateKind::Atom(atom) => atom,
+            }),
+            &ty::PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom),
         }
     }
 
@@ -1124,6 +1113,15 @@ fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHas
 #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
 #[derive(HashStable, TypeFoldable)]
 pub enum PredicateKind<'tcx> {
+    /// `for<'a>: ...`
+    ForAll(Binder<Predicate<'tcx>>),
+
+    Atom(PredicateAtom<'tcx>),
+}
+
+#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
+#[derive(HashStable, TypeFoldable)]
+pub enum PredicateAtom<'tcx> {
     /// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
     /// the `Self` type of the trait reference and `A`, `B`, and `C`
     /// would be the type parameters.
@@ -1162,9 +1160,6 @@ pub enum PredicateKind<'tcx> {
 
     /// Constants must be equal. The first component is the const that is expected.
     ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
-
-    /// `for<'a>: ...`
-    ForAll(Binder<Predicate<'tcx>>),
 }
 
 /// The crate outlives map is computed during typeck and contains the
@@ -1252,9 +1247,13 @@ pub fn subst_supertrait(
         // from the substitution and the value being substituted into, and
         // this trick achieves that).
         let substs = trait_ref.skip_binder().substs;
-        let pred = self.ignore_quantifiers().skip_binder();
+        let pred = self.skip_binders();
         let new = pred.subst(tcx, substs);
-        if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
+        if new != pred {
+            new.to_predicate(tcx).potentially_quantified(tcx, PredicateKind::ForAll)
+        } else {
+            self
+        }
     }
 }
 
@@ -1379,9 +1378,16 @@ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
     }
 }
 
+impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
+    #[inline(always)]
+    fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
+        tcx.mk_predicate(ty::PredicateKind::Atom(*self))
+    }
+}
+
 impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
     fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
-        ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
+        ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
             .to_predicate(tcx)
     }
 }
@@ -1399,94 +1405,88 @@ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
 impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         if let Some(pred) = self.value.no_bound_vars() {
-            ty::PredicateKind::Trait(pred, self.constness)
+            ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
         } else {
             ty::PredicateKind::ForAll(
                 self.value.map_bound(|pred| {
-                    ty::PredicateKind::Trait(pred, self.constness).to_predicate(tcx)
+                    ty::PredicateAtom::Trait(pred, self.constness).to_predicate(tcx)
                 }),
             )
+            .to_predicate(tcx)
         }
-        .to_predicate(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         if let Some(outlives) = self.no_bound_vars() {
-            PredicateKind::RegionOutlives(outlives)
+            PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
         } else {
             ty::PredicateKind::ForAll(
                 self.map_bound(|outlives| {
-                    PredicateKind::RegionOutlives(outlives).to_predicate(tcx)
+                    PredicateAtom::RegionOutlives(outlives).to_predicate(tcx)
                 }),
             )
+            .to_predicate(tcx)
         }
-        .to_predicate(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         if let Some(outlives) = self.no_bound_vars() {
-            PredicateKind::TypeOutlives(outlives)
+            PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)
         } else {
             ty::PredicateKind::ForAll(
-                self.map_bound(|outlives| PredicateKind::TypeOutlives(outlives).to_predicate(tcx)),
+                self.map_bound(|outlives| PredicateAtom::TypeOutlives(outlives).to_predicate(tcx)),
             )
+            .to_predicate(tcx)
         }
-        .to_predicate(tcx)
     }
 }
 
 impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
     fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
         if let Some(proj) = self.no_bound_vars() {
-            PredicateKind::Projection(proj)
+            PredicateAtom::Projection(proj).to_predicate(tcx)
         } else {
             ty::PredicateKind::ForAll(
-                self.map_bound(|proj| PredicateKind::Projection(proj).to_predicate(tcx)),
+                self.map_bound(|proj| PredicateAtom::Projection(proj).to_predicate(tcx)),
             )
+            .to_predicate(tcx)
         }
-        .to_predicate(tcx)
     }
 }
 
 impl<'tcx> Predicate<'tcx> {
     pub fn to_opt_poly_trait_ref(self) -> Option<PolyTraitRef<'tcx>> {
-        self.ignore_quantifiers()
-            .map_bound(|pred| match pred.kind() {
-                &PredicateKind::Trait(ref t, _) => Some(t.trait_ref),
-                PredicateKind::Projection(..)
-                | PredicateKind::Subtype(..)
-                | PredicateKind::RegionOutlives(..)
-                | PredicateKind::WellFormed(..)
-                | PredicateKind::ObjectSafe(..)
-                | PredicateKind::ClosureKind(..)
-                | PredicateKind::TypeOutlives(..)
-                | PredicateKind::ConstEvaluatable(..)
-                | PredicateKind::ConstEquate(..) => None,
-                PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
-            })
-            .transpose()
+        match self.skip_binders() {
+            PredicateAtom::Trait(t, _) => Some(ty::Binder::bind(t.trait_ref)),
+            PredicateAtom::Projection(..)
+            | PredicateAtom::Subtype(..)
+            | PredicateAtom::RegionOutlives(..)
+            | PredicateAtom::WellFormed(..)
+            | PredicateAtom::ObjectSafe(..)
+            | PredicateAtom::ClosureKind(..)
+            | PredicateAtom::TypeOutlives(..)
+            | PredicateAtom::ConstEvaluatable(..)
+            | PredicateAtom::ConstEquate(..) => None,
+        }
     }
 
     pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
-        self.ignore_quantifiers()
-            .map_bound(|pred| match pred.kind() {
-                &PredicateKind::TypeOutlives(data) => Some(data),
-                PredicateKind::Trait(..)
-                | PredicateKind::Projection(..)
-                | PredicateKind::Subtype(..)
-                | PredicateKind::RegionOutlives(..)
-                | PredicateKind::WellFormed(..)
-                | PredicateKind::ObjectSafe(..)
-                | PredicateKind::ClosureKind(..)
-                | PredicateKind::ConstEvaluatable(..)
-                | PredicateKind::ConstEquate(..) => None,
-                PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
-            })
-            .transpose()
+        match self.skip_binders() {
+            PredicateAtom::TypeOutlives(data) => Some(ty::Binder::bind(data)),
+            PredicateAtom::Trait(..)
+            | PredicateAtom::Projection(..)
+            | PredicateAtom::Subtype(..)
+            | PredicateAtom::RegionOutlives(..)
+            | PredicateAtom::WellFormed(..)
+            | PredicateAtom::ObjectSafe(..)
+            | PredicateAtom::ClosureKind(..)
+            | PredicateAtom::ConstEvaluatable(..)
+            | PredicateAtom::ConstEquate(..) => None,
+        }
     }
 }
 
index d22a0e8c38e040809e695483ace3b01ae6023f50..b0de57e15cc12ac53df4fbe6fdd09e7b97f5de70 100644 (file)
@@ -576,10 +576,8 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
                         // may contain unbound variables. We therefore do this manually.
                         //
                         // FIXME(lcnr): Find out why exactly this is the case :)
-                        if let ty::PredicateKind::Trait(pred, _) = predicate
-                            .ignore_quantifiers_with_unbound_vars(self.tcx())
-                            .skip_binder()
-                            .kind()
+                        if let ty::PredicateAtom::Trait(pred, _) =
+                            predicate.bound_atom(self.tcx()).skip_binder()
                         {
                             let trait_ref = ty::Binder::bind(pred.trait_ref);
                             // Don't print +Sized, but rather +?Sized if absent.
@@ -2015,38 +2013,40 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
 
     ty::Predicate<'tcx> {
         match self.kind() {
-            &ty::PredicateKind::Trait(ref data, constness) => {
-                if let hir::Constness::Const = constness {
-                    p!(write("const "));
+            &ty::PredicateKind::Atom(atom) => match atom {
+                ty::PredicateAtom::Trait(ref data, constness) => {
+                    if let hir::Constness::Const = constness {
+                        p!(write("const "));
+                    }
+                    p!(print(data))
+                }
+                ty::PredicateAtom::Subtype(predicate) => p!(print(predicate)),
+                ty::PredicateAtom::RegionOutlives(predicate) => p!(print(predicate)),
+                ty::PredicateAtom::TypeOutlives(predicate) => p!(print(predicate)),
+                ty::PredicateAtom::Projection(predicate) => p!(print(predicate)),
+                ty::PredicateAtom::WellFormed(arg) => p!(print(arg), write(" well-formed")),
+                ty::PredicateAtom::ObjectSafe(trait_def_id) => {
+                    p!(write("the trait `"),
+                    print_def_path(trait_def_id, &[]),
+                    write("` is object-safe"))
+                }
+                ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => {
+                    p!(write("the closure `"),
+                    print_value_path(closure_def_id, &[]),
+                    write("` implements the trait `{}`", kind))
+                }
+                ty::PredicateAtom::ConstEvaluatable(def, substs) => {
+                    p!(write("the constant `"),
+                    print_value_path(def.did, substs),
+                    write("` can be evaluated"))
+                }
+                ty::PredicateAtom::ConstEquate(c1, c2) => {
+                    p!(write("the constant `"),
+                    print(c1),
+                    write("` equals `"),
+                    print(c2),
+                    write("`"))
                 }
-                p!(print(data))
-            }
-            ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
-            ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
-            ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
-            ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
-            ty::PredicateKind::WellFormed(arg) => p!(print(arg), write(" well-formed")),
-            &ty::PredicateKind::ObjectSafe(trait_def_id) => {
-                p!(write("the trait `"),
-                   print_def_path(trait_def_id, &[]),
-                   write("` is object-safe"))
-            }
-            &ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
-                p!(write("the closure `"),
-                   print_value_path(closure_def_id, &[]),
-                   write("` implements the trait `{}`", kind))
-            }
-            &ty::PredicateKind::ConstEvaluatable(def, substs) => {
-                p!(write("the constant `"),
-                   print_value_path(def.did, substs),
-                   write("` can be evaluated"))
-            }
-            ty::PredicateKind::ConstEquate(c1, c2) => {
-                p!(write("the constant `"),
-                   print(c1),
-                   write("` equals `"),
-                   print(c2),
-                   write("`"))
             }
             ty::PredicateKind::ForAll(binder) => {
                 p!(print(binder))
index e6237853f21cd4f0c15c9013a8290b5d65a39ad3..cfe076e12070267024cc1046aed8f3b85cbac3c4 100644 (file)
@@ -226,28 +226,36 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl fmt::Debug for ty::PredicateKind<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            ty::PredicateKind::Trait(ref a, constness) => {
+            ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
+            ty::PredicateKind::Atom(atom) => write!(f, "{:?}", atom),
+        }
+    }
+}
+
+impl fmt::Debug for ty::PredicateAtom<'tcx> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            ty::PredicateAtom::Trait(ref a, constness) => {
                 if let hir::Constness::Const = constness {
                     write!(f, "const ")?;
                 }
                 a.fmt(f)
             }
-            ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
-            ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
-            ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
-            ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
-            ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
-            ty::PredicateKind::ObjectSafe(trait_def_id) => {
+            ty::PredicateAtom::Subtype(ref pair) => pair.fmt(f),
+            ty::PredicateAtom::RegionOutlives(ref pair) => pair.fmt(f),
+            ty::PredicateAtom::TypeOutlives(ref pair) => pair.fmt(f),
+            ty::PredicateAtom::Projection(ref pair) => pair.fmt(f),
+            ty::PredicateAtom::WellFormed(data) => write!(f, "WellFormed({:?})", data),
+            ty::PredicateAtom::ObjectSafe(trait_def_id) => {
                 write!(f, "ObjectSafe({:?})", trait_def_id)
             }
-            ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
+            ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
                 write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
             }
-            ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
+            ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
                 write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
             }
-            ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
-            ty::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder),
+            ty::PredicateAtom::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
         }
     }
 }
@@ -479,36 +487,45 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
     type Lifted = ty::PredicateKind<'tcx>;
     fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
         match *self {
-            ty::PredicateKind::Trait(ref data, constness) => {
-                tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness))
+            ty::PredicateKind::ForAll(ref binder) => {
+                tcx.lift(binder).map(ty::PredicateKind::ForAll)
+            }
+            ty::PredicateKind::Atom(ref atom) => tcx.lift(atom).map(ty::PredicateKind::Atom),
+        }
+    }
+}
+
+impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
+    type Lifted = ty::PredicateAtom<'tcx>;
+    fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
+        match *self {
+            ty::PredicateAtom::Trait(ref data, constness) => {
+                tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness))
             }
-            ty::PredicateKind::Subtype(ref data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
-            ty::PredicateKind::RegionOutlives(ref data) => {
-                tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
+            ty::PredicateAtom::Subtype(ref data) => tcx.lift(data).map(ty::PredicateAtom::Subtype),
+            ty::PredicateAtom::RegionOutlives(ref data) => {
+                tcx.lift(data).map(ty::PredicateAtom::RegionOutlives)
             }
-            ty::PredicateKind::TypeOutlives(ref data) => {
-                tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
+            ty::PredicateAtom::TypeOutlives(ref data) => {
+                tcx.lift(data).map(ty::PredicateAtom::TypeOutlives)
             }
-            ty::PredicateKind::Projection(ref data) => {
-                tcx.lift(data).map(ty::PredicateKind::Projection)
+            ty::PredicateAtom::Projection(ref data) => {
+                tcx.lift(data).map(ty::PredicateAtom::Projection)
             }
-            ty::PredicateKind::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateKind::WellFormed),
-            ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
+            ty::PredicateAtom::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateAtom::WellFormed),
+            ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
                 tcx.lift(&closure_substs).map(|closure_substs| {
-                    ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
+                    ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind)
                 })
             }
-            ty::PredicateKind::ObjectSafe(trait_def_id) => {
-                Some(ty::PredicateKind::ObjectSafe(trait_def_id))
-            }
-            ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
-                tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs))
+            ty::PredicateAtom::ObjectSafe(trait_def_id) => {
+                Some(ty::PredicateAtom::ObjectSafe(trait_def_id))
             }
-            ty::PredicateKind::ConstEquate(c1, c2) => {
-                tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
+            ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
+                tcx.lift(&substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs))
             }
-            ty::PredicateKind::ForAll(ref binder) => {
-                tcx.lift(binder).map(ty::PredicateKind::ForAll)
+            ty::PredicateAtom::ConstEquate(c1, c2) => {
+                tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
             }
         }
     }
index ffeec8758c46f0a9244e0266c2be563aff384b47..a0d99ac33c04ee1a226b24fe7bb66100ae341f27 100644 (file)
@@ -589,8 +589,8 @@ fn add_static_impl_trait_suggestion(
 
                     let mut found = false;
                     for predicate in bounds.predicates {
-                        if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) =
-                            predicate.ignore_quantifiers().skip_binder().kind()
+                        if let ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_, r)) =
+                            predicate.skip_binders()
                         {
                             if let ty::RegionKind::ReStatic = r {
                                 found = true;
index 8fdedd72c483f532c915446e24a9ef0152b233a8..bc5c144cd742c42fb81df884d39f33f1896f97cf 100644 (file)
@@ -1021,7 +1021,7 @@ fn check_user_type_annotations(&mut self) {
                     }
 
                     self.prove_predicate(
-                        ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
+                        ty::PredicateAtom::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
                         Locations::All(span),
                         ConstraintCategory::TypeAnnotation,
                     );
@@ -1273,7 +1273,7 @@ fn eq_opaque_type_and_type(
                     obligations.obligations.push(traits::Obligation::new(
                         ObligationCause::dummy(),
                         param_env,
-                        ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
+                        ty::PredicateAtom::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
                     ));
                     obligations.add(
                         infcx
@@ -1617,7 +1617,7 @@ fn check_terminator(
                 self.check_call_dest(body, term, &sig, destination, term_location);
 
                 self.prove_predicates(
-                    sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
+                    sig.inputs_and_output.iter().map(|ty| ty::PredicateAtom::WellFormed(ty.into())),
                     term_location.to_locations(),
                     ConstraintCategory::Boring,
                 );
@@ -2702,7 +2702,7 @@ fn prove_trait_ref(
         category: ConstraintCategory,
     ) {
         self.prove_predicates(
-            Some(ty::PredicateKind::Trait(
+            Some(ty::PredicateAtom::Trait(
                 ty::TraitPredicate { trait_ref },
                 hir::Constness::NotConst,
             )),
index 69e8c6b5d2acbe9ac957c4d766b550387ab4a2cd..de7d7f27186f2b4f59a772db0dd7b3fcc7ad096f 100644 (file)
@@ -24,24 +24,23 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
     loop {
         let predicates = tcx.predicates_of(current);
         for (predicate, _) in predicates.predicates {
-            match predicate.ignore_quantifiers().skip_binder().kind() {
-                ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
-                ty::PredicateKind::RegionOutlives(_)
-                | ty::PredicateKind::TypeOutlives(_)
-                | ty::PredicateKind::WellFormed(_)
-                | ty::PredicateKind::Projection(_)
-                | ty::PredicateKind::ConstEvaluatable(..)
-                | ty::PredicateKind::ConstEquate(..) => continue,
-                ty::PredicateKind::ObjectSafe(_) => {
+            match predicate.skip_binders() {
+                ty::PredicateAtom::RegionOutlives(_)
+                | ty::PredicateAtom::TypeOutlives(_)
+                | ty::PredicateAtom::WellFormed(_)
+                | ty::PredicateAtom::Projection(_)
+                | ty::PredicateAtom::ConstEvaluatable(..)
+                | ty::PredicateAtom::ConstEquate(..) => continue,
+                ty::PredicateAtom::ObjectSafe(_) => {
                     bug!("object safe predicate on function: {:#?}", predicate)
                 }
-                ty::PredicateKind::ClosureKind(..) => {
+                ty::PredicateAtom::ClosureKind(..) => {
                     bug!("closure kind predicate on function: {:#?}", predicate)
                 }
-                ty::PredicateKind::Subtype(_) => {
+                ty::PredicateAtom::Subtype(_) => {
                     bug!("subtype predicate on function: {:#?}", predicate)
                 }
-                &ty::PredicateKind::Trait(pred, constness) => {
+                ty::PredicateAtom::Trait(pred, constness) => {
                     if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
                         continue;
                     }
index 223e92e0482cde6b9441e5aeddeb970801060cc9..9c5fb4ce73450198d6ac4de1c29acc0b811da637 100644 (file)
@@ -85,23 +85,18 @@ fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> bool {
     }
 
     fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> bool {
-        match predicate.kind() {
-            &ty::PredicateKind::ForAll(pred) => {
-                // This visitor does not care about bound regions as we only
-                // look at `DefId`s.
-                self.visit_predicate(pred.skip_binder())
-            }
-            &ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
+        match predicate.skip_binders() {
+            ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref }, _) => {
                 self.visit_trait(trait_ref)
             }
-            &ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
+            ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
                 ty.visit_with(self)
                     || self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx()))
             }
-            &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
+            ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
                 ty.visit_with(self)
             }
-            ty::PredicateKind::RegionOutlives(..) => false,
+            ty::PredicateAtom::RegionOutlives(..) => false,
             _ => bug!("unexpected predicate: {:?}", predicate),
         }
     }
index 1067ca20a174fd84f3e5b193b7b2409337b8af26..b84ad93341e8186f773a51d7e94501d8da3cb7a5 100644 (file)
@@ -1154,9 +1154,7 @@ fn fold_opaque_ty(
         debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
 
         for predicate in &bounds.predicates {
-            if let ty::PredicateKind::Projection(projection) =
-                predicate.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Projection(projection) = predicate.skip_binders() {
                 if projection.ty.references_error() {
                     // No point on adding these obligations since there's a type error involved.
                     return ty_var;
@@ -1254,18 +1252,17 @@ pub fn may_define_opaque_type(
     traits::elaborate_predicates(tcx, predicates)
         .filter_map(|obligation| {
             debug!("required_region_bounds(obligation={:?})", obligation);
-            match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                ty::PredicateKind::Projection(..)
-                | ty::PredicateKind::Trait(..)
-                | ty::PredicateKind::Subtype(..)
-                | ty::PredicateKind::WellFormed(..)
-                | ty::PredicateKind::ObjectSafe(..)
-                | ty::PredicateKind::ClosureKind(..)
-                | ty::PredicateKind::RegionOutlives(..)
-                | ty::PredicateKind::ConstEvaluatable(..)
-                | ty::PredicateKind::ConstEquate(..) => None,
-                ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", obligation),
-                ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
+            match obligation.predicate.skip_binders() {
+                ty::PredicateAtom::Projection(..)
+                | ty::PredicateAtom::Trait(..)
+                | ty::PredicateAtom::Subtype(..)
+                | ty::PredicateAtom::WellFormed(..)
+                | ty::PredicateAtom::ObjectSafe(..)
+                | ty::PredicateAtom::ClosureKind(..)
+                | ty::PredicateAtom::RegionOutlives(..)
+                | ty::PredicateAtom::ConstEvaluatable(..)
+                | ty::PredicateAtom::ConstEquate(..) => None,
+                ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => {
                     // Search for a bound of the form `erased_self_ty
                     // : 'a`, but be wary of something like `for<'a>
                     // erased_self_ty : 'a` (we interpret a
index b5bea9724283dcadaff1e42a56f8232fd0f1c71c..6fe67509660bc33e413080dfd465e8f28d1f9cbc 100644 (file)
@@ -415,12 +415,10 @@ fn add_user_pred(
         let mut should_add_new = true;
         user_computed_preds.retain(|&old_pred| {
             if let (
-                ty::PredicateKind::Trait(new_trait, _),
-                ty::PredicateKind::Trait(old_trait, _),
-            ) = (
-                new_pred.ignore_quantifiers().skip_binder().kind(),
-                old_pred.ignore_quantifiers().skip_binder().kind(),
-            ) {
+                ty::PredicateAtom::Trait(new_trait, _),
+                ty::PredicateAtom::Trait(old_trait, _),
+            ) = (new_pred.skip_binders(), old_pred.skip_binders())
+            {
                 if new_trait.def_id() == old_trait.def_id() {
                     let new_substs = new_trait.trait_ref.substs;
                     let old_substs = old_trait.trait_ref.substs;
@@ -639,8 +637,8 @@ fn evaluate_nested_obligations(
             // We check this by calling is_of_param on the relevant types
             // from the various possible predicates
 
-            match predicate.ignore_quantifiers().skip_binder().kind() {
-                &ty::PredicateKind::Trait(p, _) => {
+            match predicate.skip_binders() {
+                ty::PredicateAtom::Trait(p, _) => {
                     if self.is_param_no_infer(p.trait_ref.substs)
                         && !only_projections
                         && is_new_pred
@@ -649,7 +647,7 @@ fn evaluate_nested_obligations(
                     }
                     predicates.push_back(ty::Binder::bind(p));
                 }
-                &ty::PredicateKind::Projection(p) => {
+                ty::PredicateAtom::Projection(p) => {
                     let p = ty::Binder::bind(p);
                     debug!(
                         "evaluate_nested_obligations: examining projection predicate {:?}",
@@ -775,13 +773,13 @@ fn evaluate_nested_obligations(
                         }
                     }
                 }
-                &ty::PredicateKind::RegionOutlives(binder) => {
+                ty::PredicateAtom::RegionOutlives(binder) => {
                     let binder = ty::Binder::bind(binder);
                     if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() {
                         return false;
                     }
                 }
-                &ty::PredicateKind::TypeOutlives(binder) => {
+                ty::PredicateAtom::TypeOutlives(binder) => {
                     let binder = ty::Binder::bind(binder);
                     match (
                         binder.no_bound_vars(),
index 8af4e12bd2b0f1f574708fc2f132b39ea51f067c..951e0b2202666748ec2590f5c886ef2e16256375 100644 (file)
@@ -256,11 +256,8 @@ fn report_selection_error(
                     return;
                 }
 
-                match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                    ty::PredicateKind::ForAll(_) => {
-                        bug!("unexpected predicate: {:?}", obligation.predicate)
-                    }
-                    &ty::PredicateKind::Trait(trait_predicate, _) => {
+                match obligation.predicate.skip_binders() {
+                    ty::PredicateAtom::Trait(trait_predicate, _) => {
                         let trait_predicate = ty::Binder::bind(trait_predicate);
                         let trait_predicate = self.resolve_vars_if_possible(&trait_predicate);
 
@@ -525,14 +522,14 @@ fn report_selection_error(
                         err
                     }
 
-                    ty::PredicateKind::Subtype(predicate) => {
+                    ty::PredicateAtom::Subtype(predicate) => {
                         // Errors for Subtype predicates show up as
                         // `FulfillmentErrorCode::CodeSubtypeError`,
                         // not selection error.
                         span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate)
                     }
 
-                    &ty::PredicateKind::RegionOutlives(predicate) => {
+                    ty::PredicateAtom::RegionOutlives(predicate) => {
                         let predicate = ty::Binder::bind(predicate);
                         let predicate = self.resolve_vars_if_possible(&predicate);
                         let err = self
@@ -549,7 +546,7 @@ fn report_selection_error(
                         )
                     }
 
-                    ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => {
+                    ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => {
                         let predicate = self.resolve_vars_if_possible(&obligation.predicate);
                         struct_span_err!(
                             self.tcx.sess,
@@ -560,12 +557,12 @@ fn report_selection_error(
                         )
                     }
 
-                    &ty::PredicateKind::ObjectSafe(trait_def_id) => {
+                    ty::PredicateAtom::ObjectSafe(trait_def_id) => {
                         let violations = self.tcx.object_safety_violations(trait_def_id);
                         report_object_safety_error(self.tcx, span, trait_def_id, violations)
                     }
 
-                    &ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
+                    ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => {
                         let found_kind = self.closure_kind(closure_substs).unwrap();
                         let closure_span =
                             self.tcx.sess.source_map().guess_head_span(
@@ -624,7 +621,7 @@ fn report_selection_error(
                         return;
                     }
 
-                    ty::PredicateKind::WellFormed(ty) => {
+                    ty::PredicateAtom::WellFormed(ty) => {
                         if !self.tcx.sess.opts.debugging_opts.chalk {
                             // WF predicates cannot themselves make
                             // errors. They can only block due to
@@ -642,7 +639,7 @@ fn report_selection_error(
                         }
                     }
 
-                    ty::PredicateKind::ConstEvaluatable(..) => {
+                    ty::PredicateAtom::ConstEvaluatable(..) => {
                         // Errors for `ConstEvaluatable` predicates show up as
                         // `SelectionError::ConstEvalFailure`,
                         // not `Unimplemented`.
@@ -653,7 +650,7 @@ fn report_selection_error(
                         )
                     }
 
-                    ty::PredicateKind::ConstEquate(..) => {
+                    ty::PredicateAtom::ConstEquate(..) => {
                         // Errors for `ConstEquate` predicates show up as
                         // `SelectionError::ConstEvalFailure`,
                         // not `Unimplemented`.
@@ -1090,11 +1087,8 @@ fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -
         }
 
         // FIXME: It should be possible to deal with `ForAll` in a cleaner way.
-        let (cond, error) = match (
-            cond.ignore_quantifiers().skip_binder().kind(),
-            error.ignore_quantifiers().skip_binder().kind(),
-        ) {
-            (ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(error, _)) => {
+        let (cond, error) = match (cond.skip_binders(), error.skip_binders()) {
+            (ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
                 (cond, ty::Binder::bind(error))
             }
             _ => {
@@ -1104,9 +1098,7 @@ fn error_implies(&self, cond: ty::Predicate<'tcx>, error: ty::Predicate<'tcx>) -
         };
 
         for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
-            if let &ty::PredicateKind::Trait(implication, _) =
-                obligation.predicate.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Trait(implication, _) = obligation.predicate.skip_binders() {
                 let error = error.to_poly_trait_ref();
                 let implication = ty::Binder::bind(implication).to_poly_trait_ref();
                 // FIXME: I'm just not taking associated types at all here.
@@ -1186,9 +1178,7 @@ fn report_projection_error(
             //
             // this can fail if the problem was higher-ranked, in which
             // cause I have no idea for a good error message.
-            if let &ty::PredicateKind::Projection(data) =
-                predicate.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
                 let mut selcx = SelectionContext::new(self);
                 let (data, _) = self.replace_bound_vars_with_fresh_vars(
                     obligation.cause.span,
@@ -1480,8 +1470,8 @@ fn maybe_report_ambiguity(
             return;
         }
 
-        let mut err = match predicate.ignore_quantifiers().skip_binder().kind() {
-            &ty::PredicateKind::Trait(data, _) => {
+        let mut err = match predicate.skip_binders() {
+            ty::PredicateAtom::Trait(data, _) => {
                 let trait_ref = ty::Binder::bind(data.trait_ref);
                 let self_ty = trait_ref.skip_binder().self_ty();
                 debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref);
@@ -1580,7 +1570,7 @@ fn maybe_report_ambiguity(
                 err
             }
 
-            ty::PredicateKind::WellFormed(arg) => {
+            ty::PredicateAtom::WellFormed(arg) => {
                 // Same hacky approach as above to avoid deluging user
                 // with error messages.
                 if arg.references_error() || self.tcx.sess.has_errors() {
@@ -1600,17 +1590,17 @@ fn maybe_report_ambiguity(
                 }
             }
 
-            ty::PredicateKind::Subtype(data) => {
+            ty::PredicateAtom::Subtype(data) => {
                 if data.references_error() || self.tcx.sess.has_errors() {
                     // no need to overload user in such cases
                     return;
                 }
-                let &SubtypePredicate { a_is_expected: _, a, b } = data;
+                let SubtypePredicate { a_is_expected: _, a, b } = data;
                 // both must be type variables, or the other would've been instantiated
                 assert!(a.is_ty_var() && b.is_ty_var());
                 self.need_type_info_err(body_id, span, a, ErrorCode::E0282)
             }
-            &ty::PredicateKind::Projection(data) => {
+            ty::PredicateAtom::Projection(data) => {
                 let trait_ref = ty::Binder::bind(data).to_poly_trait_ref(self.tcx);
                 let self_ty = trait_ref.skip_binder().self_ty();
                 let ty = data.ty;
@@ -1733,16 +1723,14 @@ fn suggest_unsized_bound_if_applicable(
         err: &mut DiagnosticBuilder<'tcx>,
         obligation: &PredicateObligation<'tcx>,
     ) {
-        let (pred, item_def_id, span) = match (
-            obligation.predicate.ignore_quantifiers().skip_binder().kind(),
-            obligation.cause.code.peel_derives(),
-        ) {
-            (
-                ty::PredicateKind::Trait(pred, _),
-                &ObligationCauseCode::BindingObligation(item_def_id, span),
-            ) => (pred, item_def_id, span),
-            _ => return,
-        };
+        let (pred, item_def_id, span) =
+            match (obligation.predicate.skip_binders(), obligation.cause.code.peel_derives()) {
+                (
+                    ty::PredicateAtom::Trait(pred, _),
+                    &ObligationCauseCode::BindingObligation(item_def_id, span),
+                ) => (pred, item_def_id, span),
+                _ => return,
+            };
 
         let node = match (
             self.tcx.hir().get_if_local(item_def_id),
index 9180325fb74f69409b7ea11fa454aa69229bbccf..200de47244e4f8d4c367f1badf660d6c7b3d33b5 100644 (file)
@@ -1299,11 +1299,10 @@ fn maybe_note_obligation_cause_for_async_await(
         // the type. The last generator (`outer_generator` below) has information about where the
         // bound was introduced. At least one generator should be present for this diagnostic to be
         // modified.
-        let (mut trait_ref, mut target_ty) =
-            match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
-                _ => (None, None),
-            };
+        let (mut trait_ref, mut target_ty) = match obligation.predicate.skip_binders() {
+            ty::PredicateAtom::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())),
+            _ => (None, None),
+        };
         let mut generator = None;
         let mut outer_generator = None;
         let mut next_code = Some(&obligation.cause.code);
index 995be1d90de36b16a8996beab1bd818c0b9add17..0f6f362490604c73a4ef519bfe3d96cfc71f342f 100644 (file)
@@ -320,11 +320,44 @@ fn process_obligation(
 
         match obligation.predicate.kind() {
             ty::PredicateKind::ForAll(binder) => match binder.skip_binder().kind() {
+                ty::PredicateKind::ForAll(_) => bug!("unexpected forall"),
                 // Evaluation will discard candidates using the leak check.
                 // This means we need to pass it the bound version of our
                 // predicate.
-                ty::PredicateKind::Trait(trait_ref, _constness) => {
-                    let trait_obligation = obligation.with(Binder::bind(*trait_ref));
+                &ty::PredicateKind::Atom(atom) => match atom {
+                    ty::PredicateAtom::Trait(trait_ref, _constness) => {
+                        let trait_obligation = obligation.with(Binder::bind(trait_ref));
+
+                        self.process_trait_obligation(
+                            obligation,
+                            trait_obligation,
+                            &mut pending_obligation.stalled_on,
+                        )
+                    }
+                    ty::PredicateAtom::Projection(projection) => {
+                        let project_obligation = obligation.with(Binder::bind(projection));
+
+                        self.process_projection_obligation(
+                            project_obligation,
+                            &mut pending_obligation.stalled_on,
+                        )
+                    }
+                    ty::PredicateAtom::RegionOutlives(_)
+                    | ty::PredicateAtom::TypeOutlives(_)
+                    | ty::PredicateAtom::WellFormed(_)
+                    | ty::PredicateAtom::ObjectSafe(_)
+                    | ty::PredicateAtom::ClosureKind(..)
+                    | ty::PredicateAtom::Subtype(_)
+                    | ty::PredicateAtom::ConstEvaluatable(..)
+                    | ty::PredicateAtom::ConstEquate(..) => {
+                        let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
+                        ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
+                    }
+                },
+            },
+            &ty::PredicateKind::Atom(atom) => match atom {
+                ty::PredicateAtom::Trait(ref data, _) => {
+                    let trait_obligation = obligation.with(Binder::dummy(*data));
 
                     self.process_trait_obligation(
                         obligation,
@@ -332,142 +365,112 @@ fn process_obligation(
                         &mut pending_obligation.stalled_on,
                     )
                 }
-                ty::PredicateKind::Projection(projection) => {
-                    let project_obligation = obligation.with(Binder::bind(*projection));
-
-                    self.process_projection_obligation(
-                        project_obligation,
-                        &mut pending_obligation.stalled_on,
-                    )
-                }
-                ty::PredicateKind::RegionOutlives(_)
-                | ty::PredicateKind::TypeOutlives(_)
-                | ty::PredicateKind::WellFormed(_)
-                | ty::PredicateKind::ObjectSafe(_)
-                | ty::PredicateKind::ClosureKind(..)
-                | ty::PredicateKind::Subtype(_)
-                | ty::PredicateKind::ConstEvaluatable(..)
-                | ty::PredicateKind::ConstEquate(..)
-                | ty::PredicateKind::ForAll(_) => {
-                    let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
-                    ProcessResult::Changed(mk_pending(vec![obligation.with(pred)]))
-                }
-            },
-            ty::PredicateKind::Trait(ref data, _) => {
-                let trait_obligation = obligation.with(Binder::dummy(*data));
-
-                self.process_trait_obligation(
-                    obligation,
-                    trait_obligation,
-                    &mut pending_obligation.stalled_on,
-                )
-            }
 
-            &ty::PredicateKind::RegionOutlives(data) => {
-                match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
-                    Ok(()) => ProcessResult::Changed(vec![]),
-                    Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
+                ty::PredicateAtom::RegionOutlives(data) => {
+                    match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
+                        Ok(()) => ProcessResult::Changed(vec![]),
+                        Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
+                    }
                 }
-            }
 
-            ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
-                if self.register_region_obligations {
-                    self.selcx.infcx().register_region_obligation_with_cause(
-                        t_a,
-                        r_b,
-                        &obligation.cause,
-                    );
+                ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
+                    if self.register_region_obligations {
+                        self.selcx.infcx().register_region_obligation_with_cause(
+                            t_a,
+                            r_b,
+                            &obligation.cause,
+                        );
+                    }
+                    ProcessResult::Changed(vec![])
                 }
-                ProcessResult::Changed(vec![])
-            }
 
-            ty::PredicateKind::Projection(ref data) => {
-                let project_obligation = obligation.with(Binder::dummy(*data));
+                ty::PredicateAtom::Projection(ref data) => {
+                    let project_obligation = obligation.with(Binder::dummy(*data));
 
-                self.process_projection_obligation(
-                    project_obligation,
-                    &mut pending_obligation.stalled_on,
-                )
-            }
+                    self.process_projection_obligation(
+                        project_obligation,
+                        &mut pending_obligation.stalled_on,
+                    )
+                }
 
-            &ty::PredicateKind::ObjectSafe(trait_def_id) => {
-                if !self.selcx.tcx().is_object_safe(trait_def_id) {
-                    ProcessResult::Error(CodeSelectionError(Unimplemented))
-                } else {
-                    ProcessResult::Changed(vec![])
+                ty::PredicateAtom::ObjectSafe(trait_def_id) => {
+                    if !self.selcx.tcx().is_object_safe(trait_def_id) {
+                        ProcessResult::Error(CodeSelectionError(Unimplemented))
+                    } else {
+                        ProcessResult::Changed(vec![])
+                    }
                 }
-            }
 
-            &ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
-                match self.selcx.infcx().closure_kind(closure_substs) {
-                    Some(closure_kind) => {
-                        if closure_kind.extends(kind) {
-                            ProcessResult::Changed(vec![])
-                        } else {
-                            ProcessResult::Error(CodeSelectionError(Unimplemented))
+                ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
+                    match self.selcx.infcx().closure_kind(closure_substs) {
+                        Some(closure_kind) => {
+                            if closure_kind.extends(kind) {
+                                ProcessResult::Changed(vec![])
+                            } else {
+                                ProcessResult::Error(CodeSelectionError(Unimplemented))
+                            }
                         }
+                        None => ProcessResult::Unchanged,
                     }
-                    None => ProcessResult::Unchanged,
                 }
-            }
 
-            &ty::PredicateKind::WellFormed(arg) => {
-                match wf::obligations(
-                    self.selcx.infcx(),
-                    obligation.param_env,
-                    obligation.cause.body_id,
-                    arg,
-                    obligation.cause.span,
-                ) {
-                    None => {
-                        pending_obligation.stalled_on =
-                            vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
-                        ProcessResult::Unchanged
+                ty::PredicateAtom::WellFormed(arg) => {
+                    match wf::obligations(
+                        self.selcx.infcx(),
+                        obligation.param_env,
+                        obligation.cause.body_id,
+                        arg,
+                        obligation.cause.span,
+                    ) {
+                        None => {
+                            pending_obligation.stalled_on =
+                                vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
+                            ProcessResult::Unchanged
+                        }
+                        Some(os) => ProcessResult::Changed(mk_pending(os)),
                     }
-                    Some(os) => ProcessResult::Changed(mk_pending(os)),
                 }
-            }
 
-            &ty::PredicateKind::Subtype(subtype) => {
-                match self.selcx.infcx().subtype_predicate(
-                    &obligation.cause,
-                    obligation.param_env,
-                    Binder::dummy(subtype),
-                ) {
-                    None => {
-                        // None means that both are unresolved.
-                        pending_obligation.stalled_on = vec![
-                            TyOrConstInferVar::maybe_from_ty(subtype.a).unwrap(),
-                            TyOrConstInferVar::maybe_from_ty(subtype.b).unwrap(),
-                        ];
-                        ProcessResult::Unchanged
-                    }
-                    Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
-                    Some(Err(err)) => {
-                        let expected_found =
-                            ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
-                        ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
-                            expected_found,
-                            err,
-                        ))
+                ty::PredicateAtom::Subtype(subtype) => {
+                    match self.selcx.infcx().subtype_predicate(
+                        &obligation.cause,
+                        obligation.param_env,
+                        Binder::dummy(subtype),
+                    ) {
+                        None => {
+                            // None means that both are unresolved.
+                            pending_obligation.stalled_on = vec![
+                                TyOrConstInferVar::maybe_from_ty(subtype.a).unwrap(),
+                                TyOrConstInferVar::maybe_from_ty(subtype.b).unwrap(),
+                            ];
+                            ProcessResult::Unchanged
+                        }
+                        Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
+                        Some(Err(err)) => {
+                            let expected_found =
+                                ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
+                            ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
+                                expected_found,
+                                err,
+                            ))
+                        }
                     }
                 }
-            }
 
-            &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
-                match self.selcx.infcx().const_eval_resolve(
-                    obligation.param_env,
-                    def_id,
-                    substs,
-                    None,
-                    Some(obligation.cause.span),
-                ) {
-                    Ok(_) => ProcessResult::Changed(vec![]),
-                    Err(err) => ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))),
+                ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
+                    match self.selcx.infcx().const_eval_resolve(
+                        obligation.param_env,
+                        def_id,
+                        substs,
+                        None,
+                        Some(obligation.cause.span),
+                    ) {
+                        Ok(_) => ProcessResult::Changed(vec![]),
+                        Err(err) => ProcessResult::Error(CodeSelectionError(ConstEvalFailure(err))),
+                    }
                 }
-            }
 
-            ty::PredicateKind::ConstEquate(c1, c2) => {
+            ty::PredicateAtom::ConstEquate(c1, c2) => {
                 debug!("equating consts: c1={:?} c2={:?}", c1, c2);
 
                 let stalled_on = &mut pending_obligation.stalled_on;
@@ -491,43 +494,46 @@ fn process_obligation(
                                 );
                                 Err(ErrorHandled::TooGeneric)
                             }
-                            Err(err) => Err(err),
+                        } else {
+                            Ok(c)
                         }
-                    } else {
-                        Ok(c)
-                    }
-                };
-
-                match (evaluate(c1), evaluate(c2)) {
-                    (Ok(c1), Ok(c2)) => {
-                        match self
-                            .selcx
-                            .infcx()
-                            .at(&obligation.cause, obligation.param_env)
-                            .eq(c1, c2)
-                        {
-                            Ok(_) => ProcessResult::Changed(vec![]),
-                            Err(err) => {
-                                ProcessResult::Error(FulfillmentErrorCode::CodeConstEquateError(
-                                    ExpectedFound::new(true, c1, c2),
-                                    err,
-                                ))
+                    };
+
+                    match (evaluate(c1), evaluate(c2)) {
+                        (Ok(c1), Ok(c2)) => {
+                            match self
+                                .selcx
+                                .infcx()
+                                .at(&obligation.cause, obligation.param_env)
+                                .eq(c1, c2)
+                            {
+                                Ok(_) => ProcessResult::Changed(vec![]),
+                                Err(err) => ProcessResult::Error(
+                                    FulfillmentErrorCode::CodeConstEquateError(
+                                        ExpectedFound::new(true, c1, c2),
+                                        err,
+                                    ),
+                                ),
                             }
                         }
-                    }
-                    (Err(ErrorHandled::Reported(ErrorReported)), _)
-                    | (_, Err(ErrorHandled::Reported(ErrorReported))) => ProcessResult::Error(
-                        CodeSelectionError(ConstEvalFailure(ErrorHandled::Reported(ErrorReported))),
-                    ),
-                    (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => span_bug!(
-                        obligation.cause.span(self.selcx.tcx()),
-                        "ConstEquate: const_eval_resolve returned an unexpected error"
-                    ),
-                    (Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
-                        ProcessResult::Unchanged
+                        (Err(ErrorHandled::Reported(ErrorReported)), _)
+                        | (_, Err(ErrorHandled::Reported(ErrorReported))) => {
+                            ProcessResult::Error(CodeSelectionError(ConstEvalFailure(
+                                ErrorHandled::Reported(ErrorReported),
+                            )))
+                        }
+                        (Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
+                            span_bug!(
+                                obligation.cause.span(self.selcx.tcx()),
+                                "ConstEquate: const_eval_resolve returned an unexpected error"
+                            )
+                        }
+                        (Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
+                            ProcessResult::Unchanged
+                        }
                     }
                 }
-            }
+            },
         }
     }
 
index bd0ba5570c7bb4f688bd5dd85d39d2d621a1e5b1..afa48c2f76cf8a0fb79b77e4a6a246518c7e68a1 100644 (file)
@@ -328,8 +328,8 @@ pub fn normalize_param_env_or_error<'tcx>(
     // This works fairly well because trait matching  does not actually care about param-env
     // TypeOutlives predicates - these are normally used by regionck.
     let outlives_predicates: Vec<_> = predicates
-        .drain_filter(|predicate| match predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::TypeOutlives(..) => true,
+        .drain_filter(|predicate| match predicate.skip_binders() {
+            ty::PredicateAtom::TypeOutlives(..) => true,
             _ => false,
         })
         .collect();
index 8da5e7318c002268baeacfa72164377c49bf578b..c003e4f8068738ce725d8861838f1199530602a9 100644 (file)
@@ -245,12 +245,12 @@ fn predicates_reference_self(
         .iter()
         .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
         .filter_map(|(predicate, &sp)| {
-            match predicate.ignore_quantifiers().skip_binder().kind() {
-                ty::PredicateKind::Trait(ref data, _) => {
+            match predicate.skip_binders() {
+                ty::PredicateAtom::Trait(ref data, _) => {
                     // In the case of a trait predicate, we can skip the "self" type.
                     if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
                 }
-                ty::PredicateKind::Projection(ref data) => {
+                ty::PredicateAtom::Projection(ref data) => {
                     // And similarly for projections. This should be redundant with
                     // the previous check because any projection should have a
                     // matching `Trait` predicate with the same inputs, but we do
@@ -269,15 +269,14 @@ fn predicates_reference_self(
                         None
                     }
                 }
-                ty::PredicateKind::WellFormed(..)
-                | ty::PredicateKind::ObjectSafe(..)
-                | ty::PredicateKind::TypeOutlives(..)
-                | ty::PredicateKind::RegionOutlives(..)
-                | ty::PredicateKind::ClosureKind(..)
-                | ty::PredicateKind::Subtype(..)
-                | ty::PredicateKind::ConstEvaluatable(..)
-                | ty::PredicateKind::ConstEquate(..) => None,
-                ty::PredicateKind::ForAll(..) => bug!("unexpected predicate: {:?}", predicate),
+                ty::PredicateAtom::WellFormed(..)
+                | ty::PredicateAtom::ObjectSafe(..)
+                | ty::PredicateAtom::TypeOutlives(..)
+                | ty::PredicateAtom::RegionOutlives(..)
+                | ty::PredicateAtom::ClosureKind(..)
+                | ty::PredicateAtom::Subtype(..)
+                | ty::PredicateAtom::ConstEvaluatable(..)
+                | ty::PredicateAtom::ConstEquate(..) => None,
             }
         })
         .collect()
@@ -299,22 +298,19 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
     let predicates = tcx.predicates_of(def_id);
     let predicates = predicates.instantiate_identity(tcx).predicates;
     elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
-        match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::Trait(ref trait_pred, _) => {
+        match obligation.predicate.skip_binders() {
+            ty::PredicateAtom::Trait(ref trait_pred, _) => {
                 trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
             }
-            ty::PredicateKind::Projection(..)
-            | ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::RegionOutlives(..)
-            | ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::TypeOutlives(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => false,
-            ty::PredicateKind::ForAll(_) => {
-                bug!("unexpected predicate: {:?}", obligation.predicate)
-            }
+            ty::PredicateAtom::Projection(..)
+            | ty::PredicateAtom::Subtype(..)
+            | ty::PredicateAtom::RegionOutlives(..)
+            | ty::PredicateAtom::WellFormed(..)
+            | ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::TypeOutlives(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => false,
         }
     })
 }
index c12f9eb112f9d39f26054bf114015c3cd5a7a709..717b7e2fe574f05c7da7942b98e5d4fa0b4dd034 100644 (file)
@@ -665,7 +665,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
         .obligations
         .iter()
         .filter(|obligation| {
-            match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
+            match obligation.predicate.skip_binders() {
                 // We found a `T: Foo<X = U>` predicate, let's check
                 // if `U` references any unresolved type
                 // variables. In principle, we only care if this
@@ -675,7 +675,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
                 // indirect obligations (e.g., we project to `?0`,
                 // but we have `T: Foo<X = ?1>` and `?1: Bar<X =
                 // ?0>`).
-                &ty::PredicateKind::Projection(data) => {
+                ty::PredicateAtom::Projection(data) => {
                     infcx.unresolved_type_vars(&ty::Binder::bind(data.ty)).is_some()
                 }
 
@@ -933,9 +933,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
     let infcx = selcx.infcx();
     for predicate in env_predicates {
         debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
-        if let &ty::PredicateKind::Projection(data) =
-            predicate.ignore_quantifiers().skip_binder().kind()
-        {
+        if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
             let data = ty::Binder::bind(data);
             let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
 
@@ -1227,15 +1225,13 @@ fn confirm_object_candidate<'cx, 'tcx>(
         // select only those projections that are actually projecting an
         // item with the correct name
 
-        let env_predicates = env_predicates.filter_map(|o| {
-            match o.predicate.ignore_quantifiers().skip_binder().kind() {
-                &ty::PredicateKind::Projection(data)
-                    if data.projection_ty.item_def_id == obligation.predicate.item_def_id =>
-                {
-                    Some(ty::Binder::bind(data))
-                }
-                _ => None,
+        let env_predicates = env_predicates.filter_map(|o| match o.predicate.skip_binders() {
+            ty::PredicateAtom::Projection(data)
+                if data.projection_ty.item_def_id == obligation.predicate.item_def_id =>
+            {
+                Some(ty::Binder::bind(data))
             }
+            _ => None,
         });
 
         // select those with a relevant trait-ref
index 24551299df252649a45038b004f5c38a96f42b09..93ddcb6855400b5cb95571d8d136df5143d483a1 100644 (file)
@@ -15,9 +15,7 @@ fn try_fast_path(
         // `&T`, accounts for about 60% percentage of the predicates
         // we have to prove. No need to canonicalize and all that for
         // such cases.
-        if let ty::PredicateKind::Trait(trait_ref, _) =
-            key.value.predicate.ignore_quantifiers().skip_binder().kind()
-        {
+        if let ty::PredicateAtom::Trait(trait_ref, _) = key.value.predicate.skip_binders() {
             if let Some(sized_def_id) = tcx.lang_items().sized_trait() {
                 if trait_ref.def_id() == sized_def_id {
                     if trait_ref.self_ty().is_trivially_sized(tcx) {
index fa970589bbbf60399b801884cd6ccb94db9572da..a04636af5796a0d96b5ce4b036119344c344d6bd 100644 (file)
@@ -532,7 +532,7 @@ fn confirm_closure_candidate(
             obligations.push(Obligation::new(
                 obligation.cause.clone(),
                 obligation.param_env,
-                ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
+                ty::PredicateAtom::ClosureKind(closure_def_id, substs, kind)
                     .to_predicate(self.tcx()),
             ));
         }
index 4b1e2013feff22a65debe776580d0d8939c8277b..4123f2938261c6478e92a14e79a8d425fff26ac8 100644 (file)
@@ -408,18 +408,15 @@ fn evaluate_predicate_recursively<'o>(
             None => self.check_recursion_limit(&obligation, &obligation)?,
         }
 
-        match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::ForAll(_) => {
-                bug!("unexpected predicate: {:?}", obligation.predicate)
-            }
-            &ty::PredicateKind::Trait(t, _) => {
+        match obligation.predicate.skip_binders() {
+            ty::PredicateAtom::Trait(t, _) => {
                 let t = ty::Binder::bind(t);
                 debug_assert!(!t.has_escaping_bound_vars());
                 let obligation = obligation.with(t);
                 self.evaluate_trait_predicate_recursively(previous_stack, obligation)
             }
 
-            &ty::PredicateKind::Subtype(p) => {
+            ty::PredicateAtom::Subtype(p) => {
                 let p = ty::Binder::bind(p);
                 // Does this code ever run?
                 match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
@@ -435,7 +432,7 @@ fn evaluate_predicate_recursively<'o>(
                 }
             }
 
-            &ty::PredicateKind::WellFormed(arg) => match wf::obligations(
+            ty::PredicateAtom::WellFormed(arg) => match wf::obligations(
                 self.infcx,
                 obligation.param_env,
                 obligation.cause.body_id,
@@ -449,12 +446,12 @@ fn evaluate_predicate_recursively<'o>(
                 None => Ok(EvaluatedToAmbig),
             },
 
-            ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => {
+            ty::PredicateAtom::TypeOutlives(..) | ty::PredicateAtom::RegionOutlives(..) => {
                 // We do not consider region relationships when evaluating trait matches.
                 Ok(EvaluatedToOkModuloRegions)
             }
 
-            &ty::PredicateKind::ObjectSafe(trait_def_id) => {
+            ty::PredicateAtom::ObjectSafe(trait_def_id) => {
                 if self.tcx().is_object_safe(trait_def_id) {
                     Ok(EvaluatedToOk)
                 } else {
@@ -462,7 +459,7 @@ fn evaluate_predicate_recursively<'o>(
                 }
             }
 
-            &ty::PredicateKind::Projection(data) => {
+            ty::PredicateAtom::Projection(data) => {
                 let data = ty::Binder::bind(data);
                 let project_obligation = obligation.with(data);
                 match project::poly_project_and_unify_type(self, &project_obligation) {
@@ -484,7 +481,7 @@ fn evaluate_predicate_recursively<'o>(
                 }
             }
 
-            &ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
+            ty::PredicateAtom::ClosureKind(_, closure_substs, kind) => {
                 match self.infcx.closure_kind(closure_substs) {
                     Some(closure_kind) => {
                         if closure_kind.extends(kind) {
@@ -497,7 +494,7 @@ fn evaluate_predicate_recursively<'o>(
                 }
             }
 
-            &ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
+            ty::PredicateAtom::ConstEvaluatable(def_id, substs) => {
                 match self.tcx().const_eval_resolve(
                     obligation.param_env,
                     def_id,
@@ -511,7 +508,7 @@ fn evaluate_predicate_recursively<'o>(
                 }
             }
 
-            ty::PredicateKind::ConstEquate(c1, c2) => {
+            ty::PredicateAtom::ConstEquate(c1, c2) => {
                 debug!("evaluate_predicate_recursively: equating consts c1={:?} c2={:?}", c1, c2);
 
                 let evaluate = |c: &'tcx ty::Const<'tcx>| {
@@ -792,8 +789,8 @@ pub fn coinductive_match<I>(&mut self, cycle: I) -> bool
     }
 
     fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
-        let result = match predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
+        let result = match predicate.skip_binders() {
+            ty::PredicateAtom::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
             _ => false,
         };
         debug!("coinductive_predicate({:?}) = {:?}", predicate, result);
@@ -1301,9 +1298,7 @@ fn match_projection_obligation_against_definition_bounds(
         };
 
         let matching_bound = predicates.iter().find_map(|bound| {
-            if let ty::PredicateKind::Trait(pred, _) =
-                bound.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Trait(pred, _) = bound.skip_binders() {
                 let bound = ty::Binder::bind(pred.trait_ref);
                 if self.infcx.probe(|_| {
                     self.match_projection(obligation, bound, placeholder_trait_predicate.trait_ref)
index afa2270b7af0f2b5d193cad496f023cf6ca71aa6..0ca69c0f76e7a273b865e4ea8c2ff2e2292edb2f 100644 (file)
@@ -98,38 +98,40 @@ pub fn predicate_obligations<'a, 'tcx>(
             // It's ok to skip the binder here because wf code is prepared for it
             return predicate_obligations(infcx, param_env, body_id, binder.skip_binder(), span);
         }
-        ty::PredicateKind::Trait(t, _) => {
-            wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
-        }
-        ty::PredicateKind::RegionOutlives(..) => {}
-        &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
-            wf.compute(ty.into());
-        }
-        ty::PredicateKind::Projection(t) => {
-            wf.compute_projection(t.projection_ty);
-            wf.compute(t.ty.into());
-        }
-        &ty::PredicateKind::WellFormed(arg) => {
-            wf.compute(arg);
-        }
-        ty::PredicateKind::ObjectSafe(_) => {}
-        ty::PredicateKind::ClosureKind(..) => {}
-        &ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
-            wf.compute(a.into());
-            wf.compute(b.into());
-        }
-        &ty::PredicateKind::ConstEvaluatable(def, substs) => {
-            let obligations = wf.nominal_obligations(def.did, substs);
-            wf.out.extend(obligations);
-
-            for arg in substs.iter() {
+        &ty::PredicateKind::Atom(atom) => match atom {
+            ty::PredicateAtom::Trait(t, _) => {
+                wf.compute_trait_ref(&t.trait_ref, Elaborate::None);
+            }
+            ty::PredicateAtom::RegionOutlives(..) => {}
+            ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
+                wf.compute(ty.into());
+            }
+            ty::PredicateAtom::Projection(t) => {
+                wf.compute_projection(t.projection_ty);
+                wf.compute(t.ty.into());
+            }
+            ty::PredicateAtom::WellFormed(arg) => {
                 wf.compute(arg);
             }
-        }
-        &ty::PredicateKind::ConstEquate(c1, c2) => {
-            wf.compute(c1.into());
-            wf.compute(c2.into());
-        }
+            ty::PredicateAtom::ObjectSafe(_) => {}
+            ty::PredicateAtom::ClosureKind(..) => {}
+            ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => {
+                wf.compute(a.into());
+                wf.compute(b.into());
+            }
+            ty::PredicateAtom::ConstEvaluatable(def, substs) => {
+                let obligations = wf.nominal_obligations(def.did, substs);
+                wf.out.extend(obligations);
+
+                for arg in substs.iter() {
+                    wf.compute(arg);
+                }
+            }
+            ty::PredicateAtom::ConstEquate(c1, c2) => {
+                wf.compute(c1.into());
+                wf.compute(c2.into());
+            }
+        },
     }
 
     wf.normalize()
@@ -196,8 +198,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
         };
 
     // It is fine to skip the binder as we don't care about regions here.
-    match pred.ignore_quantifiers().skip_binder().kind() {
-        ty::PredicateKind::Projection(proj) => {
+    match pred.skip_binders() {
+        ty::PredicateAtom::Projection(proj) => {
             // The obligation comes not from the current `impl` nor the `trait` being implemented,
             // but rather from a "second order" obligation, where an associated type has a
             // projection coming from another associated type. See
@@ -212,7 +214,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
                 }
             }
         }
-        ty::PredicateKind::Trait(pred, _) => {
+        ty::PredicateAtom::Trait(pred, _) => {
             // An associated item obligation born out of the `trait` failed to be met. An example
             // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
             debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
@@ -317,7 +319,7 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo
                     traits::Obligation::new(
                         new_cause,
                         param_env,
-                        ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
+                        ty::PredicateAtom::WellFormed(arg).to_predicate(tcx),
                     )
                 }),
         );
@@ -374,7 +376,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
                             let obligations = self.nominal_obligations(def.did, substs);
                             self.out.extend(obligations);
 
-                            let predicate = ty::PredicateKind::ConstEvaluatable(def, substs)
+                            let predicate = ty::PredicateAtom::ConstEvaluatable(def, substs)
                                 .to_predicate(self.tcx());
                             let cause = self.cause(traits::MiscObligation);
                             self.out.push(traits::Obligation::new(
@@ -396,7 +398,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
                                 self.out.push(traits::Obligation::new(
                                     cause,
                                     self.param_env,
-                                    ty::PredicateKind::WellFormed(resolved_constant.into())
+                                    ty::PredicateAtom::WellFormed(resolved_constant.into())
                                         .to_predicate(self.tcx()),
                                 ));
                             }
@@ -482,7 +484,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
                         self.out.push(traits::Obligation::new(
                             cause,
                             param_env,
-                            ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
+                            ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(rty, r))
                                 .to_predicate(self.tcx()),
                         ));
                     }
@@ -573,7 +575,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
                             traits::Obligation::new(
                                 cause.clone(),
                                 param_env,
-                                ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
+                                ty::PredicateAtom::ObjectSafe(did).to_predicate(tcx),
                             )
                         }));
                     }
@@ -599,7 +601,7 @@ fn compute(&mut self, arg: GenericArg<'tcx>) {
                         self.out.push(traits::Obligation::new(
                             cause,
                             param_env,
-                            ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
+                            ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()),
                         ));
                     } else {
                         // Yes, resolved, proceed with the result.
index b781c2e2a6e9a520daa136d2779eb79bcb724378..75785076d9ac1cd92d114d3fef82b720353e62b0 100644 (file)
@@ -79,13 +79,8 @@ fn lower_into(
         let clauses = self.environment.into_iter().filter_map(|clause| match clause {
             ChalkEnvironmentClause::Predicate(predicate) => {
                 // FIXME(chalk): forall
-                match predicate
-                    .ignore_quantifiers_with_unbound_vars(interner.tcx)
-                    .skip_binder()
-                    .kind()
-                {
-                    ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
-                    &ty::PredicateKind::Trait(predicate, _) => {
+                match predicate.bound_atom(interner.tcx).skip_binder() {
+                    ty::PredicateAtom::Trait(predicate, _) => {
                         let predicate = ty::Binder::bind(predicate);
                         let (predicate, binders, _named_regions) =
                             collect_bound_vars(interner, interner.tcx, &predicate);
@@ -106,7 +101,7 @@ fn lower_into(
                             .intern(interner),
                         )
                     }
-                    &ty::PredicateKind::RegionOutlives(predicate) => {
+                    ty::PredicateAtom::RegionOutlives(predicate) => {
                         let predicate = ty::Binder::bind(predicate);
                         let (predicate, binders, _named_regions) =
                             collect_bound_vars(interner, interner.tcx, &predicate);
@@ -131,8 +126,8 @@ fn lower_into(
                         )
                     }
                     // FIXME(chalk): need to add TypeOutlives
-                    ty::PredicateKind::TypeOutlives(_) => None,
-                    &ty::PredicateKind::Projection(predicate) => {
+                    ty::PredicateAtom::TypeOutlives(_) => None,
+                    ty::PredicateAtom::Projection(predicate) => {
                         let predicate = ty::Binder::bind(predicate);
                         let (predicate, binders, _named_regions) =
                             collect_bound_vars(interner, interner.tcx, &predicate);
@@ -153,12 +148,12 @@ fn lower_into(
                             .intern(interner),
                         )
                     }
-                    ty::PredicateKind::WellFormed(..)
-                    | ty::PredicateKind::ObjectSafe(..)
-                    | ty::PredicateKind::ClosureKind(..)
-                    | ty::PredicateKind::Subtype(..)
-                    | ty::PredicateKind::ConstEvaluatable(..)
-                    | ty::PredicateKind::ConstEquate(..) => {
+                    ty::PredicateAtom::WellFormed(..)
+                    | ty::PredicateAtom::ObjectSafe(..)
+                    | ty::PredicateAtom::ClosureKind(..)
+                    | ty::PredicateAtom::Subtype(..)
+                    | ty::PredicateAtom::ConstEvaluatable(..)
+                    | ty::PredicateAtom::ConstEquate(..) => {
                         bug!("unexpected predicate {}", predicate)
                     }
                 }
@@ -191,12 +186,11 @@ fn lower_into(
 impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> {
     fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> {
         // FIXME(chalk): forall
-        match self.ignore_quantifiers_with_unbound_vars(interner.tcx).skip_binder().kind() {
-            ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
-            &ty::PredicateKind::Trait(predicate, _) => {
+        match self.bound_atom(interner.tcx).skip_binder() {
+            ty::PredicateAtom::Trait(predicate, _) => {
                 ty::Binder::bind(predicate).lower_into(interner)
             }
-            &ty::PredicateKind::RegionOutlives(predicate) => {
+            ty::PredicateAtom::RegionOutlives(predicate) => {
                 let predicate = ty::Binder::bind(predicate);
                 let (predicate, binders, _named_regions) =
                     collect_bound_vars(interner, interner.tcx, &predicate);
@@ -216,13 +210,13 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
                 )
             }
             // FIXME(chalk): TypeOutlives
-            ty::PredicateKind::TypeOutlives(_predicate) => {
+            ty::PredicateAtom::TypeOutlives(_predicate) => {
                 chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
             }
-            &ty::PredicateKind::Projection(predicate) => {
+            ty::PredicateAtom::Projection(predicate) => {
                 ty::Binder::bind(predicate).lower_into(interner)
             }
-            ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
+            ty::PredicateAtom::WellFormed(arg) => match arg.unpack() {
                 GenericArgKind::Type(ty) => match ty.kind {
                     // FIXME(chalk): In Chalk, a placeholder is WellFormed if it
                     // `FromEnv`. However, when we "lower" Params, we don't update
@@ -252,18 +246,18 @@ fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInt
                 GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
             },
 
-            ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
-                chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(*t)),
+            ty::PredicateAtom::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
+                chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(t)),
             ),
 
             // FIXME(chalk): other predicates
             //
             // We can defer this, but ultimately we'll want to express
             // some of these in terms of chalk operations.
-            ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => {
+            ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::Subtype(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => {
                 chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
             }
         }
@@ -561,9 +555,8 @@ fn lower_into(
         interner: &RustInterner<'tcx>,
     ) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
         // FIXME(chalk): forall
-        match self.ignore_quantifiers_with_unbound_vars(interner.tcx).skip_binder().kind() {
-            ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", self),
-            &ty::PredicateKind::Trait(predicate, _) => {
+        match self.bound_atom(interner.tcx).skip_binder() {
+            ty::PredicateAtom::Trait(predicate, _) => {
                 let predicate = ty::Binder::bind(predicate);
                 let (predicate, binders, _named_regions) =
                     collect_bound_vars(interner, interner.tcx, &predicate);
@@ -573,7 +566,7 @@ fn lower_into(
                     chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)),
                 ))
             }
-            &ty::PredicateKind::RegionOutlives(predicate) => {
+            ty::PredicateAtom::RegionOutlives(predicate) => {
                 let predicate = ty::Binder::bind(predicate);
                 let (predicate, binders, _named_regions) =
                     collect_bound_vars(interner, interner.tcx, &predicate);
@@ -586,15 +579,15 @@ fn lower_into(
                     }),
                 ))
             }
-            ty::PredicateKind::TypeOutlives(_predicate) => None,
-            ty::PredicateKind::Projection(_predicate) => None,
-            ty::PredicateKind::WellFormed(_ty) => None,
-
-            ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self),
+            ty::PredicateAtom::TypeOutlives(_predicate) => None,
+            ty::PredicateAtom::Projection(_predicate) => None,
+            ty::PredicateAtom::WellFormed(_ty) => None,
+
+            ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::Subtype(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
         }
     }
 }
index 26a44bb5c2f1b8abd1326b8449018e736190212a..de3096eac9b193df599036065968bbcfe796ac73 100644 (file)
@@ -95,29 +95,31 @@ fn compute_implied_outlives_bounds<'tcx>(
         implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
             assert!(!obligation.has_escaping_bound_vars());
             match obligation.predicate.kind() {
-                ty::PredicateKind::ForAll(..) => vec![],
-                ty::PredicateKind::Trait(..)
-                | ty::PredicateKind::Subtype(..)
-                | ty::PredicateKind::Projection(..)
-                | ty::PredicateKind::ClosureKind(..)
-                | ty::PredicateKind::ObjectSafe(..)
-                | ty::PredicateKind::ConstEvaluatable(..)
-                | ty::PredicateKind::ConstEquate(..) => vec![],
-                &ty::PredicateKind::WellFormed(arg) => {
-                    wf_args.push(arg);
-                    vec![]
-                }
+                &ty::PredicateKind::ForAll(..) => vec![],
+                &ty::PredicateKind::Atom(atom) => match atom {
+                    ty::PredicateAtom::Trait(..)
+                    | ty::PredicateAtom::Subtype(..)
+                    | ty::PredicateAtom::Projection(..)
+                    | ty::PredicateAtom::ClosureKind(..)
+                    | ty::PredicateAtom::ObjectSafe(..)
+                    | ty::PredicateAtom::ConstEvaluatable(..)
+                    | ty::PredicateAtom::ConstEquate(..) => vec![],
+                    ty::PredicateAtom::WellFormed(arg) => {
+                        wf_args.push(arg);
+                        vec![]
+                    }
 
-                &ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
-                    vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
-                }
+                    ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
+                        vec![OutlivesBound::RegionSubRegion(r_b, r_a)]
+                    }
 
-                &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
-                    let ty_a = infcx.resolve_vars_if_possible(&ty_a);
-                    let mut components = smallvec![];
-                    tcx.push_outlives_components(ty_a, &mut components);
-                    implied_bounds_from_components(r_b, components)
-                }
+                    ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
+                        let ty_a = infcx.resolve_vars_if_possible(&ty_a);
+                        let mut components = smallvec![];
+                        tcx.push_outlives_components(ty_a, &mut components);
+                        implied_bounds_from_components(r_b, components)
+                    }
+                },
             }
         }));
     }
index cefc20972143acf72e2b1469de3f58ecceaa95e4..83aee31a39f3c223ae6af037ac29ebda5cacc3b2 100644 (file)
@@ -40,16 +40,15 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
 }
 
 fn not_outlives_predicate(p: &ty::Predicate<'tcx>) -> bool {
-    match p.ignore_quantifiers().skip_binder().kind() {
-        ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
-        ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", p),
-        ty::PredicateKind::Trait(..)
-        | ty::PredicateKind::Projection(..)
-        | ty::PredicateKind::WellFormed(..)
-        | ty::PredicateKind::ObjectSafe(..)
-        | ty::PredicateKind::ClosureKind(..)
-        | ty::PredicateKind::Subtype(..)
-        | ty::PredicateKind::ConstEvaluatable(..)
-        | ty::PredicateKind::ConstEquate(..) => true,
+    match p.skip_binders() {
+        ty::PredicateAtom::RegionOutlives(..) | ty::PredicateAtom::TypeOutlives(..) => false,
+        ty::PredicateAtom::Trait(..)
+        | ty::PredicateAtom::Projection(..)
+        | ty::PredicateAtom::WellFormed(..)
+        | ty::PredicateAtom::ObjectSafe(..)
+        | ty::PredicateAtom::ClosureKind(..)
+        | ty::PredicateAtom::Subtype(..)
+        | ty::PredicateAtom::ConstEvaluatable(..)
+        | ty::PredicateAtom::ConstEquate(..) => true,
     }
 }
index 9cc9a35b38b8adfb5b9293cb89f147cdb8197214..139ed6dcd350c8b616b936b0599f8fbbab049dd9 100644 (file)
@@ -140,7 +140,7 @@ fn relate_mir_and_user_ty(
             self.relate(self_ty, Variance::Invariant, impl_self_ty)?;
 
             self.prove_predicate(
-                ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
+                ty::PredicateAtom::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
             );
         }
 
@@ -155,7 +155,7 @@ fn relate_mir_and_user_ty(
         // them?  This would only be relevant if some input
         // type were ill-formed but did not appear in `ty`,
         // which...could happen with normalization...
-        self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()));
+        self.prove_predicate(ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()));
         Ok(())
     }
 }
index 48802893926b7a9845fdc5d780176d1dc423b9a4..7f954dacf3e893c4a3b96bf9a9d0c2ad6c74fce0 100644 (file)
@@ -392,22 +392,22 @@ fn associated_type_projection_predicates(
 
     let predicates = item_predicates.filter_map(|obligation| {
         let pred = obligation.predicate;
-        match pred.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::Trait(tr, _) => {
+        match pred.skip_binders() {
+            ty::PredicateAtom::Trait(tr, _) => {
                 if let ty::Projection(p) = tr.self_ty().kind {
                     if p == assoc_item_ty {
                         return Some(pred);
                     }
                 }
             }
-            ty::PredicateKind::Projection(proj) => {
+            ty::PredicateAtom::Projection(proj) => {
                 if let ty::Projection(p) = proj.projection_ty.self_ty().kind {
                     if p == assoc_item_ty {
                         return Some(pred);
                     }
                 }
             }
-            ty::PredicateKind::TypeOutlives(outlives) => {
+            ty::PredicateAtom::TypeOutlives(outlives) => {
                 if let ty::Projection(p) = outlives.0.kind {
                     if p == assoc_item_ty {
                         return Some(pred);
@@ -443,15 +443,15 @@ fn opaque_type_projection_predicates(
 
     let filtered_predicates = predicates.filter_map(|obligation| {
         let pred = obligation.predicate;
-        match pred.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::Trait(tr, _) => {
+        match pred.skip_binders() {
+            ty::PredicateAtom::Trait(tr, _) => {
                 if let ty::Opaque(opaque_def_id, opaque_substs) = tr.self_ty().kind {
                     if opaque_def_id == def_id && opaque_substs == substs {
                         return Some(pred);
                     }
                 }
             }
-            ty::PredicateKind::Projection(proj) => {
+            ty::PredicateAtom::Projection(proj) => {
                 if let ty::Opaque(opaque_def_id, opaque_substs) = proj.projection_ty.self_ty().kind
                 {
                     if opaque_def_id == def_id && opaque_substs == substs {
@@ -459,7 +459,7 @@ fn opaque_type_projection_predicates(
                     }
                 }
             }
-            ty::PredicateKind::TypeOutlives(outlives) => {
+            ty::PredicateAtom::TypeOutlives(outlives) => {
                 if let ty::Opaque(opaque_def_id, opaque_substs) = outlives.0.kind {
                     if opaque_def_id == def_id && opaque_substs == substs {
                         return Some(pred);
@@ -470,7 +470,7 @@ fn opaque_type_projection_predicates(
                 }
             }
             // These can come from elaborating other predicates
-            ty::PredicateKind::RegionOutlives(_) => return None,
+            ty::PredicateAtom::RegionOutlives(_) => return None,
             _ => {}
         }
         tcx.sess.delay_span_bug(
index 841bfbfba7028aba2261b4b05d2cb8a7b7f63978..79d2f104a525fe32b2a796e046b0a982ae4e293a 100644 (file)
@@ -1706,8 +1706,8 @@ fn conv_object_ty_poly_trait_ref(
                     obligation.predicate
                 );
 
-                match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                    &ty::PredicateKind::Trait(pred, _) => {
+                match obligation.predicate.skip_binders() {
+                    ty::PredicateAtom::Trait(pred, _) => {
                         let pred = ty::Binder::bind(pred);
                         associated_types.entry(span).or_default().extend(
                             tcx.associated_items(pred.def_id())
@@ -1716,7 +1716,7 @@ fn conv_object_ty_poly_trait_ref(
                                 .map(|item| item.def_id),
                         );
                     }
-                    &ty::PredicateKind::Projection(pred) => {
+                    ty::PredicateAtom::Projection(pred) => {
                         let pred = ty::Binder::bind(pred);
                         // A `Self` within the original bound will be substituted with a
                         // `trait_object_dummy_self`, so check for that.
index 6b7848c2eb982eef3c485369265ddd0745209a5d..255f611cfa3572c2f5aca33850d0b608afb36e39 100644 (file)
@@ -206,8 +206,8 @@ fn deduce_expectations_from_obligations(
                     obligation.predicate
                 );
 
-                if let &ty::PredicateKind::Projection(proj_predicate) =
-                    obligation.predicate.ignore_quantifiers().skip_binder().kind()
+                if let ty::PredicateAtom::Projection(proj_predicate) =
+                    obligation.predicate.skip_binders()
                 {
                     // Given a Projection predicate, we can potentially infer
                     // the complete signature.
@@ -631,8 +631,8 @@ fn deduce_future_output_from_obligations(&self, expr_def_id: DefId) -> Option<Ty
         // where R is the return type we are expecting. This type `T`
         // will be our output.
         let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
-            if let &ty::PredicateKind::Projection(proj_predicate) =
-                obligation.predicate.ignore_quantifiers().skip_binder().kind()
+            if let ty::PredicateAtom::Projection(proj_predicate) =
+                obligation.predicate.skip_binders()
             {
                 self.deduce_future_output_from_projection(
                     obligation.cause.span,
index 2b6362230f83691a8593796e374546d2a3c311b2..c7e9b97e2dbde3565f4af38b03a9bb5827edc8fb 100644 (file)
@@ -582,8 +582,8 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
         while !queue.is_empty() {
             let obligation = queue.remove(0);
             debug!("coerce_unsized resolve step: {:?}", obligation);
-            let trait_pred = match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                &ty::PredicateKind::Trait(trait_pred, _)
+            let trait_pred = match obligation.predicate.skip_binders() {
+                ty::PredicateAtom::Trait(trait_pred, _)
                     if traits.contains(&trait_pred.def_id()) =>
                 {
                     if unsize_did == trait_pred.def_id() {
index 4bbdb2a5ad3db060b8f3df443863e6d758dd519e..88c47b38ccc40b4e3ade7e772416e6304abd54f0 100644 (file)
@@ -226,14 +226,11 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
         // could be extended easily also to the other `Predicate`.
         let predicate_matches_closure = |p: Predicate<'tcx>| {
             let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
-            match (
-                predicate.ignore_quantifiers().skip_binder().kind(),
-                p.ignore_quantifiers().skip_binder().kind(),
-            ) {
-                (&ty::PredicateKind::Trait(a, _), &ty::PredicateKind::Trait(b, _)) => {
+            match (predicate.skip_binders(), p.skip_binders()) {
+                (ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
                     relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
                 }
-                (&ty::PredicateKind::Projection(a), &ty::PredicateKind::Projection(b)) => {
+                (ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
                     relator.relate(ty::Binder::bind(a), ty::Binder::bind(b)).is_ok()
                 }
                 _ => predicate == p,
index b97dd8bf348f5ff7f17e5dc73bd364709b23b5ff..41e37ee9752521cd91c6ee644175b7fe536a94e0 100644 (file)
@@ -448,24 +448,21 @@ fn predicates_require_illegal_sized_bound(
 
         traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
             // We don't care about regions here.
-            .filter_map(|obligation| {
-                match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                    ty::PredicateKind::Trait(trait_pred, _)
-                        if trait_pred.def_id() == sized_def_id =>
-                    {
-                        let span =
-                            predicates
-                                .predicates
-                                .iter()
-                                .zip(predicates.spans.iter())
-                                .find_map(|(p, span)| {
-                                    if *p == obligation.predicate { Some(*span) } else { None }
-                                })
-                                .unwrap_or(rustc_span::DUMMY_SP);
-                        Some((trait_pred, span))
-                    }
-                    _ => None,
+            .filter_map(|obligation| match obligation.predicate.skip_binders() {
+                ty::PredicateAtom::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => {
+                    let span = predicates
+                        .predicates
+                        .iter()
+                        .zip(predicates.spans.iter())
+                        .find_map(
+                            |(p, span)| {
+                                if *p == obligation.predicate { Some(*span) } else { None }
+                            },
+                        )
+                        .unwrap_or(rustc_span::DUMMY_SP);
+                    Some((trait_pred, span))
                 }
+                _ => None,
             })
             .find_map(|(trait_pred, span)| match trait_pred.self_ty().kind {
                 ty::Dynamic(..) => Some(span),
index 64dce3e1738e38115fd37a66536d3acc37a24fdc..c9a4df0317abcd2eb9b95a12247da93e045d239f 100644 (file)
@@ -399,7 +399,7 @@ pub fn lookup_method_in_trait(
         obligations.push(traits::Obligation::new(
             cause,
             self.param_env,
-            ty::PredicateKind::WellFormed(method_ty.into()).to_predicate(tcx),
+            ty::PredicateAtom::WellFormed(method_ty.into()).to_predicate(tcx),
         ));
 
         let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig };
index 9c5e3cbc93844a338f77c3c6977b26e59a520e63..e569d1c443a6975641748bc3e976a2775121a569 100644 (file)
@@ -798,24 +798,23 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
         // FIXME: do we want to commit to this behavior for param bounds?
         debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
 
-        let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| match predicate
-            .kind()
+        let bounds = self.param_env.caller_bounds().iter().map(ty::Predicate::skip_binders).filter_map(|predicate| match predicate
         {
-            ty::PredicateKind::Trait(ref trait_predicate, _) => {
-                match trait_predicate.skip_binder().trait_ref.self_ty().kind {
-                    ty::Param(ref p) if *p == param_ty => Some(trait_predicate.to_poly_trait_ref()),
+            ty::PredicateAtom::Trait(trait_predicate, _) => {
+                match trait_predicate.trait_ref.self_ty().kind {
+                    ty::Param(ref p) if *p == param_ty => Some(ty::Binder::bind(trait_predicate.trait_ref)),
                     _ => None,
                 }
             }
-            ty::PredicateKind::Subtype(..)
-            | ty::PredicateKind::Projection(..)
-            | ty::PredicateKind::RegionOutlives(..)
-            | ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::TypeOutlives(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => None,
+            ty::PredicateAtom::Subtype(..)
+            | ty::PredicateAtom::Projection(..)
+            | ty::PredicateAtom::RegionOutlives(..)
+            | ty::PredicateAtom::WellFormed(..)
+            | ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::TypeOutlives(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => None,
         });
 
         self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
index cedd7926290ea1906263d55b06c24723026e175e..07cc8332b84cfebb2ccf8bd972d735427324bf5d 100644 (file)
@@ -576,10 +576,9 @@ macro_rules! report_function {
                         // this is kind of ugly.
                         |self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| {
                             // We don't care about regions here, so it's fine to skip the binder here.
-                            if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = (
-                                &self_ty.kind,
-                                parent_pred.ignore_quantifiers().skip_binder().kind(),
-                            ) {
+                            if let (ty::Param(_), ty::PredicateAtom::Trait(p, _)) =
+                                (&self_ty.kind, parent_pred.skip_binders())
+                            {
                                 if let ty::Adt(def, _) = p.trait_ref.self_ty().kind {
                                     let node = def.did.as_local().map(|def_id| {
                                         self.tcx.hir().get(self.tcx.hir().as_local_hir_id(def_id))
@@ -631,8 +630,8 @@ macro_rules! report_function {
                         }
                     };
                     let mut format_pred = |pred: ty::Predicate<'tcx>| {
-                        match pred.ignore_quantifiers().skip_binder().kind() {
-                            &ty::PredicateKind::Projection(pred) => {
+                        match pred.skip_binders() {
+                            ty::PredicateAtom::Projection(pred) => {
                                 let pred = ty::Binder::bind(pred);
                                 // `<Foo as Iterator>::Item = String`.
                                 let trait_ref =
@@ -651,7 +650,7 @@ macro_rules! report_function {
                                 bound_span_label(trait_ref.self_ty(), &obligation, &quiet);
                                 Some((obligation, trait_ref.self_ty()))
                             }
-                            &ty::PredicateKind::Trait(poly_trait_ref, _) => {
+                            ty::PredicateAtom::Trait(poly_trait_ref, _) => {
                                 let poly_trait_ref = ty::Binder::bind(poly_trait_ref);
                                 let p = poly_trait_ref.skip_binder().trait_ref;
                                 let self_ty = p.self_ty();
@@ -959,11 +958,11 @@ fn suggest_traits_to_import<'b>(
                 // implementing a trait would be legal but is rejected
                 // here).
                 unsatisfied_predicates.iter().all(|(p, _)| {
-                    match p.ignore_quantifiers().skip_binder().kind() {
+                    match p.skip_binders() {
                         // Hide traits if they are present in predicates as they can be fixed without
                         // having to implement them.
-                        ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id,
-                        ty::PredicateKind::Projection(p) => {
+                        ty::PredicateAtom::Trait(t, _) => t.def_id() == info.def_id,
+                        ty::PredicateAtom::Projection(p) => {
                             p.projection_ty.item_def_id == info.def_id
                         }
                         _ => false,
index f54a59486656be39d35c1f5a1708feb2b7f6b0f0..61520e292365037c98038db79828a1c4026c8da4 100644 (file)
@@ -2400,8 +2400,8 @@ fn bounds_from_generic_predicates<'tcx>(
     let mut projections = vec![];
     for (predicate, _) in predicates.predicates {
         debug!("predicate {:?}", predicate);
-        match predicate.ignore_quantifiers().skip_binder().kind() {
-            ty::PredicateKind::Trait(trait_predicate, _) => {
+        match predicate.skip_binders() {
+            ty::PredicateAtom::Trait(trait_predicate, _) => {
                 let entry = types.entry(trait_predicate.self_ty()).or_default();
                 let def_id = trait_predicate.def_id();
                 if Some(def_id) != tcx.lang_items().sized_trait() {
@@ -2410,7 +2410,7 @@ fn bounds_from_generic_predicates<'tcx>(
                     entry.push(trait_predicate.def_id());
                 }
             }
-            ty::PredicateKind::Projection(projection_pred) => {
+            ty::PredicateAtom::Projection(projection_pred) => {
                 projections.push(ty::Binder::bind(projection_pred));
             }
             _ => {}
@@ -2938,9 +2938,9 @@ fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredic
             parent: None,
             predicates: tcx.arena.alloc_from_iter(
                 self.param_env.caller_bounds().iter().filter_map(|predicate| {
-                    match predicate.kind() {
-                        ty::PredicateKind::Trait(ref data, _)
-                            if data.skip_binder().self_ty().is_param(index) =>
+                    match predicate.skip_binders() {
+                        ty::PredicateAtom::Trait(data, _)
+                            if data.self_ty().is_param(index) =>
                         {
                             // HACK(eddyb) should get the original `Span`.
                             let span = tcx.def_span(def_id);
@@ -3612,7 +3612,7 @@ pub fn register_wf_obligation(
         self.register_predicate(traits::Obligation::new(
             cause,
             self.param_env,
-            ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx),
+            ty::PredicateAtom::WellFormed(arg).to_predicate(self.tcx),
         ));
     }
 
@@ -3894,23 +3894,20 @@ fn obligations_for_self_ty<'b>(
             .pending_obligations()
             .into_iter()
             .filter_map(move |obligation| {
-                match obligation.predicate.ignore_quantifiers().skip_binder().kind() {
-                    ty::PredicateKind::ForAll(_) => {
-                        bug!("unexpected predicate: {:?}", obligation.predicate)
-                    }
-                    &ty::PredicateKind::Projection(data) => {
+                match obligation.predicate.skip_binders() {
+                    ty::PredicateAtom::Projection(data) => {
                         Some((ty::Binder::bind(data).to_poly_trait_ref(self.tcx), obligation))
                     }
-                    &ty::PredicateKind::Trait(data, _) => {
+                    ty::PredicateAtom::Trait(data, _) => {
                         Some((ty::Binder::bind(data).to_poly_trait_ref(), obligation))
                     }
-                    ty::PredicateKind::Subtype(..) => None,
-                    ty::PredicateKind::RegionOutlives(..) => None,
-                    ty::PredicateKind::TypeOutlives(..) => None,
-                    ty::PredicateKind::WellFormed(..) => None,
-                    ty::PredicateKind::ObjectSafe(..) => None,
-                    ty::PredicateKind::ConstEvaluatable(..) => None,
-                    ty::PredicateKind::ConstEquate(..) => None,
+                    ty::PredicateAtom::Subtype(..) => None,
+                    ty::PredicateAtom::RegionOutlives(..) => None,
+                    ty::PredicateAtom::TypeOutlives(..) => None,
+                    ty::PredicateAtom::WellFormed(..) => None,
+                    ty::PredicateAtom::ObjectSafe(..) => None,
+                    ty::PredicateAtom::ConstEvaluatable(..) => None,
+                    ty::PredicateAtom::ConstEquate(..) => None,
                     // N.B., this predicate is created by breaking down a
                     // `ClosureType: FnFoo()` predicate, where
                     // `ClosureType` represents some `Closure`. It can't
@@ -3919,7 +3916,7 @@ fn obligations_for_self_ty<'b>(
                     // this closure yet; this is exactly why the other
                     // code is looking for a self type of a unresolved
                     // inference variable.
-                    ty::PredicateKind::ClosureKind(..) => None,
+                    ty::PredicateAtom::ClosureKind(..) => None,
                 }
             })
             .filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root))
@@ -4249,8 +4246,8 @@ fn point_at_arg_instead_of_call_if_possible(
                 continue;
             }
 
-            if let ty::PredicateKind::Trait(predicate, _) =
-                error.obligation.predicate.ignore_quantifiers().skip_binder().kind()
+            if let ty::PredicateAtom::Trait(predicate, _) =
+                error.obligation.predicate.skip_binders()
             {
                 // Collect the argument position for all arguments that could have caused this
                 // `FulfillmentError`.
@@ -4298,8 +4295,8 @@ fn point_at_type_arg_instead_of_call_if_possible(
             if let hir::ExprKind::Path(qpath) = &path.kind {
                 if let hir::QPath::Resolved(_, path) = &qpath {
                     for error in errors {
-                        if let ty::PredicateKind::Trait(predicate, _) =
-                            error.obligation.predicate.ignore_quantifiers().skip_binder().kind()
+                        if let ty::PredicateAtom::Trait(predicate, _) =
+                            error.obligation.predicate.skip_binders()
                         {
                             // If any of the type arguments in this path segment caused the
                             // `FullfillmentError`, point at its span (#61860).
@@ -5372,7 +5369,7 @@ fn suggest_missing_await(
                     item_def_id,
                 };
 
-                let predicate = ty::PredicateKind::Projection(ty::ProjectionPredicate {
+                let predicate = ty::PredicateAtom::Projection(ty::ProjectionPredicate {
                     projection_ty,
                     ty: expected,
                 })
index dabae6cbc41377a3fdf75e55101086b8c8da6dd8..50d9a1ebd2c249d6671862e9af6a37cfc726e959 100644 (file)
@@ -429,7 +429,7 @@ fn check_type_defn<'tcx, F>(
                 fcx.register_predicate(traits::Obligation::new(
                     cause,
                     fcx.param_env,
-                    ty::PredicateKind::ConstEvaluatable(
+                    ty::PredicateAtom::ConstEvaluatable(
                         ty::WithOptConstParam::unknown(discr_def_id.to_def_id()),
                         discr_substs,
                     )
index e5d2c569004e19fbc63a836ba43f8b48cda0933b..d906c5c05c019eadef5e1e8f87c2ceaebd8d0cb1 100644 (file)
@@ -552,8 +552,8 @@ fn type_param_predicates(
     let extra_predicates = extend.into_iter().chain(
         icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true))
             .into_iter()
-            .filter(|(predicate, _)| match predicate.ignore_quantifiers().skip_binder().kind() {
-                ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index),
+            .filter(|(predicate, _)| match predicate.skip_binders() {
+                ty::PredicateAtom::Trait(data, _) => data.self_ty().is_param(index),
                 _ => false,
             }),
     );
@@ -1004,7 +1004,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
     // which will, in turn, reach indirect supertraits.
     for &(pred, span) in superbounds {
         debug!("superbound: {:?}", pred);
-        if let ty::PredicateKind::Trait(bound, _) = pred.ignore_quantifiers().skip_binder().kind() {
+        if let ty::PredicateAtom::Trait(bound, _) = pred.skip_binders() {
             tcx.at(span).super_predicates_of(bound.def_id());
         }
     }
@@ -1960,7 +1960,7 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
                         &hir::GenericBound::Outlives(ref lifetime) => {
                             let region = AstConv::ast_region_to_region(&icx, lifetime, None);
                             predicates.push((
-                                ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region))
+                                ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
                                     .to_predicate(tcx)
                                     .potentially_quantified(tcx, ty::PredicateKind::ForAll),
                                 lifetime.span,
@@ -1979,7 +1979,7 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
                         }
                         _ => bug!(),
                     };
-                    let pred = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
+                    let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
                         .to_predicate(icx.tcx);
 
                     (pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
@@ -2110,7 +2110,7 @@ fn predicates_from_bound<'tcx>(
         }
         hir::GenericBound::Outlives(ref lifetime) => {
             let region = astconv.ast_region_to_region(lifetime, None);
-            let pred = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
+            let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
                 .to_predicate(astconv.tcx())
                 .potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
             vec![(pred, lifetime.span)]
index 7936d003f54ca23692f609dfc0e24037f1136c11..7c80315ee194d52c5cf0f183f2918c79a182e8a6 100644 (file)
@@ -182,9 +182,7 @@ pub fn setup_constraining_predicates<'tcx>(
         for j in i..predicates.len() {
             // Note that we don't have to care about binders here,
             // as the impl trait ref never contains any late-bound regions.
-            if let ty::PredicateKind::Projection(projection) =
-                predicates[j].0.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Projection(projection) = predicates[j].0.skip_binders() {
                 // Special case: watch out for some kind of sneaky attempt
                 // to project out an associated type defined by this very
                 // trait.
index 0cc99a7a54e9e611a7e7d4fb0b2f5e207441bcf0..8257c6ce92547b8d51378a9797845c1a6b8a3385 100644 (file)
@@ -198,9 +198,7 @@ fn unconstrained_parent_impl_substs<'tcx>(
     // the functions in `cgp` add the constrained parameters to a list of
     // unconstrained parameters.
     for (predicate, _) in impl_generic_predicates.predicates.iter() {
-        if let ty::PredicateKind::Projection(proj) =
-            predicate.ignore_quantifiers().skip_binder().kind()
-        {
+        if let ty::PredicateAtom::Projection(proj) = predicate.skip_binders() {
             let projection_ty = proj.projection_ty;
             let projected_ty = proj.ty;
 
@@ -361,13 +359,13 @@ fn check_predicates<'tcx>(
 
 fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, span: Span) {
     debug!("can_specialize_on(predicate = {:?})", predicate);
-    match predicate.ignore_quantifiers().skip_binder().kind() {
+    match predicate.skip_binders() {
         // Global predicates are either always true or always false, so we
         // are fine to specialize on.
         _ if predicate.is_global() => (),
         // We allow specializing on explicitly marked traits with no associated
         // items.
-        ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
+        ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
             if !matches!(
                 trait_predicate_kind(tcx, predicate),
                 Some(TraitSpecializationKind::Marker)
@@ -394,20 +392,19 @@ fn trait_predicate_kind<'tcx>(
     tcx: TyCtxt<'tcx>,
     predicate: ty::Predicate<'tcx>,
 ) -> Option<TraitSpecializationKind> {
-    match predicate.ignore_quantifiers().skip_binder().kind() {
-        ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
-        ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
+    match predicate.skip_binders() {
+        ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => {
             Some(tcx.trait_def(pred.def_id()).specialization_kind)
         }
-        ty::PredicateKind::Trait(_, hir::Constness::Const)
-        | ty::PredicateKind::RegionOutlives(_)
-        | ty::PredicateKind::TypeOutlives(_)
-        | ty::PredicateKind::Projection(_)
-        | ty::PredicateKind::WellFormed(_)
-        | ty::PredicateKind::Subtype(_)
-        | ty::PredicateKind::ObjectSafe(_)
-        | ty::PredicateKind::ClosureKind(..)
-        | ty::PredicateKind::ConstEvaluatable(..)
-        | ty::PredicateKind::ConstEquate(..) => None,
+        ty::PredicateAtom::Trait(_, hir::Constness::Const)
+        | ty::PredicateAtom::RegionOutlives(_)
+        | ty::PredicateAtom::TypeOutlives(_)
+        | ty::PredicateAtom::Projection(_)
+        | ty::PredicateAtom::WellFormed(_)
+        | ty::PredicateAtom::Subtype(_)
+        | ty::PredicateAtom::ObjectSafe(_)
+        | ty::PredicateAtom::ClosureKind(..)
+        | ty::PredicateAtom::ConstEvaluatable(..)
+        | ty::PredicateAtom::ConstEquate(..) => None,
     }
 }
index bbde0b63cbbbaded6b44f558bbebab0da076dcf2..135960a4c111414dc1f0d2e187e9890e83d16089 100644 (file)
@@ -29,10 +29,8 @@ pub fn explicit_predicates_of(
 
             // process predicates and convert to `RequiredPredicates` entry, see below
             for &(predicate, span) in predicates.predicates {
-                match predicate.ignore_quantifiers().skip_binder().kind() {
-                    ty::PredicateKind::ForAll(_) => bug!("unepected predicate: {:?}", predicate),
-
-                    ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
+                match predicate.skip_binders() {
+                    ty::PredicateAtom::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => {
                         insert_outlives_predicate(
                             tcx,
                             (*ty).into(),
@@ -42,7 +40,7 @@ pub fn explicit_predicates_of(
                         )
                     }
 
-                    ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
+                    ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => {
                         insert_outlives_predicate(
                             tcx,
                             (*reg1).into(),
@@ -52,14 +50,14 @@ pub fn explicit_predicates_of(
                         )
                     }
 
-                    ty::PredicateKind::Trait(..)
-                    | ty::PredicateKind::Projection(..)
-                    | ty::PredicateKind::WellFormed(..)
-                    | ty::PredicateKind::ObjectSafe(..)
-                    | ty::PredicateKind::ClosureKind(..)
-                    | ty::PredicateKind::Subtype(..)
-                    | ty::PredicateKind::ConstEvaluatable(..)
-                    | ty::PredicateKind::ConstEquate(..) => (),
+                    ty::PredicateAtom::Trait(..)
+                    | ty::PredicateAtom::Projection(..)
+                    | ty::PredicateAtom::WellFormed(..)
+                    | ty::PredicateAtom::ObjectSafe(..)
+                    | ty::PredicateAtom::ClosureKind(..)
+                    | ty::PredicateAtom::Subtype(..)
+                    | ty::PredicateAtom::ConstEvaluatable(..)
+                    | ty::PredicateAtom::ConstEquate(..) => (),
                 }
             }
 
index 56badb324c73e2e0e050e1e3dd7ea6c73ce820ba..823a0235b176dd45527465a1720afce2c472ec2c 100644 (file)
@@ -31,8 +31,12 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
                     let mut pred: Vec<String> = predicates
                         .iter()
                         .map(|(out_pred, _)| match out_pred.kind() {
-                            ty::PredicateKind::RegionOutlives(p) => p.to_string(),
-                            ty::PredicateKind::TypeOutlives(p) => p.to_string(),
+                            ty::PredicateKind::Atom(ty::PredicateAtom::RegionOutlives(p)) => {
+                                p.to_string()
+                            }
+                            ty::PredicateKind::Atom(ty::PredicateAtom::TypeOutlives(p)) => {
+                                p.to_string()
+                            }
                             err => bug!("unexpected predicate {:?}", err),
                         })
                         .collect();
@@ -85,13 +89,13 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
                 |(ty::OutlivesPredicate(kind1, region2), &span)| {
                     match kind1.unpack() {
                         GenericArgKind::Type(ty1) => Some((
-                            ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
+                            ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
                                 .to_predicate(tcx)
                                 .potentially_quantified(tcx, ty::PredicateKind::ForAll),
                             span,
                         )),
                         GenericArgKind::Lifetime(region1) => Some((
-                            ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
+                            ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
                                 region1, region2,
                             ))
                             .to_predicate(tcx)
index 498fa25836c95cc42cc5b03954e8fdcab3642e1e..98d8f100b27d9187bdd4504857186d4e35c6bf80 100644 (file)
@@ -315,11 +315,11 @@ fn extract_for_generics(
         tcx: TyCtxt<'tcx>,
         pred: ty::Predicate<'tcx>,
     ) -> FxHashSet<GenericParamDef> {
-        let regions = match pred.ignore_quantifiers().skip_binder().kind() {
-            &ty::PredicateKind::Trait(poly_trait_pred, _) => {
+        let regions = match pred.skip_binders() {
+            ty::PredicateAtom::Trait(poly_trait_pred, _) => {
                 tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(poly_trait_pred))
             }
-            &ty::PredicateKind::Projection(poly_proj_pred) => {
+            ty::PredicateAtom::Projection(poly_proj_pred) => {
                 tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(poly_proj_pred))
             }
             _ => return FxHashSet::default(),
@@ -465,8 +465,8 @@ fn param_env_to_generics(
             .iter()
             .filter(|p| {
                 !orig_bounds.contains(p)
-                    || match p.ignore_quantifiers().skip_binder().kind() {
-                        ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
+                    || match p.skip_binders() {
+                        ty::PredicateAtom::Trait(pred, _) => pred.def_id() == sized_trait,
                         _ => false,
                     }
             })
index a86ee12fa99b1d05c3648a8fa03232906d862fe0..728453deecff6fa4b77f4126c5cbcaedd78d21a9 100644 (file)
@@ -480,19 +480,18 @@ fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
 
 impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
     fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
-        match self.ignore_quantifiers().skip_binder().kind() {
-            &ty::PredicateKind::Trait(pred, _) => Some(ty::Binder::bind(pred).clean(cx)),
-            &ty::PredicateKind::Subtype(pred) => Some(ty::Binder::bind(pred).clean(cx)),
-            &ty::PredicateKind::RegionOutlives(pred) => ty::Binder::bind(pred).clean(cx),
-            &ty::PredicateKind::TypeOutlives(pred) => ty::Binder::bind(pred).clean(cx),
-            &ty::PredicateKind::Projection(pred) => Some(ty::Binder::bind(pred).clean(cx)),
+        match self.skip_binders() {
+            ty::PredicateAtom::Trait(pred, _) => Some(ty::Binder::bind(pred).clean(cx)),
+            ty::PredicateAtom::Subtype(pred) => Some(ty::Binder::bind(pred).clean(cx)),
+            ty::PredicateAtom::RegionOutlives(pred) => ty::Binder::bind(pred).clean(cx),
+            ty::PredicateAtom::TypeOutlives(pred) => ty::Binder::bind(pred).clean(cx),
+            ty::PredicateAtom::Projection(pred) => Some(ty::Binder::bind(pred).clean(cx)),
 
-            ty::PredicateKind::ForAll(_) => panic!("unexpected predicate: {:?}", self),
-            ty::PredicateKind::WellFormed(..)
-            | ty::PredicateKind::ObjectSafe(..)
-            | ty::PredicateKind::ClosureKind(..)
-            | ty::PredicateKind::ConstEvaluatable(..)
-            | ty::PredicateKind::ConstEquate(..) => panic!("not user writable"),
+            ty::PredicateAtom::WellFormed(..)
+            | ty::PredicateAtom::ObjectSafe(..)
+            | ty::PredicateAtom::ClosureKind(..)
+            | ty::PredicateAtom::ConstEvaluatable(..)
+            | ty::PredicateAtom::ConstEquate(..) => panic!("not user writable"),
         }
     }
 }
@@ -755,18 +754,18 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
             .flat_map(|(p, _)| {
                 let mut projection = None;
                 let param_idx = (|| {
-                    match p.ignore_quantifiers().skip_binder().kind() {
-                        &ty::PredicateKind::Trait(pred, _constness) => {
+                    match p.skip_binders() {
+                        ty::PredicateAtom::Trait(pred, _constness) => {
                             if let ty::Param(param) = pred.self_ty().kind {
                                 return Some(param.index);
                             }
                         }
-                        &ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
+                        ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
                             if let ty::Param(param) = ty.kind {
                                 return Some(param.index);
                             }
                         }
-                        &ty::PredicateKind::Projection(p) => {
+                        ty::PredicateAtom::Projection(p) => {
                             if let ty::Param(param) = p.projection_ty.self_ty().kind {
                                 projection = Some(ty::Binder::bind(p));
                                 return Some(param.index);
@@ -1663,15 +1662,11 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
                     .filter_map(|predicate| {
                         // Note: The substs of opaque types can contain unbound variables,
                         // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here.
-                        let trait_ref = match predicate
-                            .ignore_quantifiers_with_unbound_vars(cx.tcx)
-                            .skip_binder()
-                            .kind()
-                        {
-                            ty::PredicateKind::Trait(tr, _constness) => {
+                        let trait_ref = match predicate.bound_atom(cx.tcx).skip_binder() {
+                            ty::PredicateAtom::Trait(tr, _constness) => {
                                 ty::Binder::bind(tr.trait_ref)
                             }
-                            ty::PredicateKind::TypeOutlives(pred) => {
+                            ty::PredicateAtom::TypeOutlives(pred) => {
                                 if let Some(r) = pred.1.clean(cx) {
                                     regions.push(GenericBound::Outlives(r));
                                 }
@@ -1691,10 +1686,9 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
                             .predicates
                             .iter()
                             .filter_map(|pred| {
-                                if let ty::PredicateKind::Projection(proj) = pred
-                                    .ignore_quantifiers_with_unbound_vars(cx.tcx)
-                                    .skip_binder()
-                                    .kind()
+                                // We never rebind `proj`, so `skip_binders_unchecked` is safe here.
+                                if let ty::PredicateAtom::Projection(proj) =
+                                    pred.skip_binders_unchecked()
                                 {
                                     if proj.projection_ty.trait_ref(cx.tcx)
                                         == trait_ref.skip_binder()
index 98e461fe6956388f548c290afac7fd9bd1329333..0f995a60c22fd06d0247391a850ad588524251ef 100644 (file)
@@ -141,9 +141,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId)
         .predicates
         .iter()
         .filter_map(|(pred, _)| {
-            if let ty::PredicateKind::Trait(pred, _) =
-                pred.ignore_quantifiers().skip_binder().kind()
-            {
+            if let ty::PredicateAtom::Trait(pred, _) = pred.skip_binders() {
                 if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None }
             } else {
                 None
index 7eeb6a75ea7b06eb10cb40332b16b8efe702d7d3..0fdb5b8c2a48e9a6217c96f58dec7808be398e1b 100644 (file)
@@ -3,7 +3,7 @@
 use rustc_hir::{Body, FnDecl, HirId};
 use rustc_infer::infer::TyCtxtInferExt;
 use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::{Opaque, PredicateKind::Trait};
+use rustc_middle::ty::{Opaque, PredicateAtom::Trait};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::{sym, Span};
 use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@@ -91,7 +91,7 @@ fn check_fn(
                             cx.tcx.infer_ctxt().enter(|infcx| {
                                 for FulfillmentError { obligation, .. } in send_errors {
                                     infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
-                                    if let Trait(trait_pred, _) = obligation.predicate.ignore_quantifiers().skip_binder().kind() {
+                                    if let Trait(trait_pred, _) = obligation.predicate.skip_binders() {
                                         db.note(&format!(
                                             "`{}` doesn't implement `{}`",
                                             trait_pred.self_ty(),
index a450d5f16f8cb5337590c951ed098d2509bef20c..2c70183d87666d7aa0ac5ea93fc94d4406c7579d 100644 (file)
@@ -1559,7 +1559,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
             if let ty::Opaque(def_id, _) = ret_ty.kind {
                 // one of the associated types must be Self
                 for &(predicate, _span) in cx.tcx.predicates_of(def_id).predicates {
-                    if let ty::PredicateKind::Projection(projection_predicate) = predicate.ignore_quantifiers().skip_binder().kind() {
+                    if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() {
                         // walk the associated type and check for Self
                         if contains_self_ty(projection_predicate.ty) {
                             return;
index e39fb23365a27a9cadb3c29d48d619529895f2ee..095778777449831305e59398bda6ce891da4de73 100644 (file)
@@ -115,7 +115,7 @@ fn check_fn(
             .filter(|p| !p.is_global())
             .filter_map(|obligation| {
                 // Note that we do not want to deal with qualified predicates here.
-                if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() {
+                if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
                     if pred.def_id() == sized_trait {
                         return None;
                     }
index c4603418ee3c65287f392df70b72cdcf826df573..655b1133cf74f14430d2a2a3415a70a53cfde184 100644 (file)
@@ -1263,7 +1263,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
         ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
         ty::Opaque(ref def_id, _) => {
             for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
-                if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.ignore_quantifiers().skip_binder().kind() {
+                if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() {
                     if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() {
                         return true;
                     }