From d8cf8ba5f7e4154913eab3be13fd1cc0b3e06906 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 9 Jul 2020 00:35:55 +0200 Subject: [PATCH] introduce PredicateAtom --- .../infer/canonical/query_response.rs | 6 +- src/librustc_infer/infer/combine.rs | 6 +- src/librustc_infer/infer/outlives/mod.rs | 34 +- src/librustc_infer/infer/sub.rs | 2 +- src/librustc_infer/traits/util.rs | 40 +-- src/librustc_lint/builtin.rs | 13 +- src/librustc_lint/unused.rs | 4 +- src/librustc_middle/ty/flags.rs | 68 ++-- src/librustc_middle/ty/mod.rs | 166 +++++----- src/librustc_middle/ty/print/pretty.rs | 70 ++-- src/librustc_middle/ty/structural_impls.rs | 81 +++-- .../borrow_check/diagnostics/region_errors.rs | 4 +- .../borrow_check/type_check/mod.rs | 8 +- .../transform/qualify_min_const_fn.rs | 23 +- src/librustc_privacy/lib.rs | 15 +- src/librustc_trait_selection/opaque_types.rs | 27 +- .../traits/auto_trait.rs | 20 +- .../traits/error_reporting/mod.rs | 68 ++-- .../traits/error_reporting/suggestions.rs | 9 +- .../traits/fulfill.rs | 304 +++++++++--------- src/librustc_trait_selection/traits/mod.rs | 4 +- .../traits/object_safety.rs | 48 ++- .../traits/project.rs | 22 +- .../traits/query/type_op/prove_predicate.rs | 4 +- .../traits/select/confirmation.rs | 2 +- .../traits/select/mod.rs | 31 +- src/librustc_trait_selection/traits/wf.rs | 80 ++--- src/librustc_traits/chalk/lowering.rs | 77 ++--- .../implied_outlives_bounds.rs | 44 +-- .../normalize_erasing_regions.rs | 21 +- src/librustc_traits/type_op.rs | 4 +- src/librustc_ty/ty.rs | 18 +- src/librustc_typeck/astconv.rs | 6 +- src/librustc_typeck/check/closure.rs | 8 +- src/librustc_typeck/check/coercion.rs | 4 +- src/librustc_typeck/check/dropck.rs | 9 +- src/librustc_typeck/check/method/confirm.rs | 31 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 27 +- src/librustc_typeck/check/method/suggest.rs | 19 +- src/librustc_typeck/check/mod.rs | 49 ++- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/collect.rs | 12 +- .../constrained_generic_params.rs | 4 +- .../impl_wf_check/min_specialization.rs | 33 +- src/librustc_typeck/outlives/explicit.rs | 24 +- src/librustc_typeck/outlives/mod.rs | 12 +- src/librustdoc/clean/auto_trait.rs | 10 +- src/librustdoc/clean/mod.rs | 48 ++- src/librustdoc/clean/simplify.rs | 4 +- .../clippy_lints/src/future_not_send.rs | 4 +- .../clippy/clippy_lints/src/methods/mod.rs | 2 +- .../src/needless_pass_by_value.rs | 2 +- .../clippy/clippy_lints/src/utils/mod.rs | 2 +- 54 files changed, 795 insertions(+), 842 deletions(-) diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index a6229e61ae7..8406eb9bc17 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -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, }); diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index c63464e5bae..5b4d91de3ca 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -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(), diff --git a/src/librustc_infer/infer/outlives/mod.rs b/src/librustc_infer/infer/outlives/mod.rs index 541a2f18045..6009d4e6579 100644 --- a/src/librustc_infer/infer/outlives/mod.rs +++ b/src/librustc_infer/infer/outlives/mod.rs @@ -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> + '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)) + } + }) } diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 5ad08f0b895..4f860c77d65 100644 --- a/src/librustc_infer/infer/sub.rs +++ b/src/librustc_infer/infer/sub.rs @@ -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, diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index 0d343be2c26..93fc7f1f3b8 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -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 { 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, ))) } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 00d532c7ba0..d67be44e4f0 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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> { 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> { 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, diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 8f21cb51695..dcb44ab6444 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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 = diff --git a/src/librustc_middle/ty/flags.rs b/src/librustc_middle/ty/flags.rs index 4b1f970edb0..7452089658f 100644 --- a/src/librustc_middle/ty/flags.rs +++ b/src/librustc_middle/ty/flags.rs @@ -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); + } + }, } } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index c8ad8ae10dc..0ff475fb288 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -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> { + /// 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> { + /// 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> { 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>), + + Atom(PredicateAtom<'tcx>), +} + +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(HashStable, TypeFoldable)] +pub enum PredicateAtom<'tcx> { /// Corresponds to `where Foo: Bar`. `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>), } /// 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> { 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> { 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> { - 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> { - 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, + } } } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index d22a0e8c38e..b0de57e15cc 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -576,10 +576,8 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result // 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 { 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)) diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index e6237853f21..cfe076e1207 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -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 { 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 { + 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)) } } } diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index ffeec8758c4..a0d99ac33c0 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -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; diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 8fdedd72c48..bc5c144cd74 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -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, )), diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 69e8c6b5d2a..de7d7f27186 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -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; } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 223e92e0482..9c5fb4ce734 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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), } } diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 1067ca20a17..b84ad93341e 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -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 diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index b5bea972428..6fe67509660 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -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(), diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 8af4e12bd2b..951e0b22026 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -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), diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 9180325fb74..200de47244e 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -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); diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 995be1d90de..0f6f3624906 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -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 + } } } - } + }, } } diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index bd0ba5570c7..afa48c2f76c 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -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(); diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 8da5e7318c0..c003e4f8068 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -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, } }) } diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index c12f9eb112f..717b7e2fe57 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -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` 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` and `?1: Bar`). - &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 diff --git a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs index 24551299df2..93ddcb68554 100644 --- a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs +++ b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs @@ -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) { diff --git a/src/librustc_trait_selection/traits/select/confirmation.rs b/src/librustc_trait_selection/traits/select/confirmation.rs index fa970589bbb..a04636af579 100644 --- a/src/librustc_trait_selection/traits/select/confirmation.rs +++ b/src/librustc_trait_selection/traits/select/confirmation.rs @@ -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()), )); } diff --git a/src/librustc_trait_selection/traits/select/mod.rs b/src/librustc_trait_selection/traits/select/mod.rs index 4b1e2013fef..4123f293826 100644 --- a/src/librustc_trait_selection/traits/select/mod.rs +++ b/src/librustc_trait_selection/traits/select/mod.rs @@ -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(&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) diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index afa2270b7af..0ca69c0f76e 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -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. diff --git a/src/librustc_traits/chalk/lowering.rs b/src/librustc_traits/chalk/lowering.rs index b781c2e2a6e..75785076d9a 100644 --- a/src/librustc_traits/chalk/lowering.rs +++ b/src/librustc_traits/chalk/lowering.rs @@ -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>> for ty::Predicate<'tcx> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData> { // 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 { + 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 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>> { // 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), } } } diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index 26a44bb5c2f..de3096eac9b 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -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) + } + }, } })); } diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index cefc2097214..83aee31a39f 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -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, } } diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 9cc9a35b38b..139ed6dcd35 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -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(()) } } diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 48802893926..7f954dacf3e 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -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( diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 841bfbfba70..79d2f104a52 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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. diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 6b7848c2eb9..255f611cfa3 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -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, 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() { diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 4bbdb2a5ad3..88c47b38ccc 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -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, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index b97dd8bf348..41e37ee9752 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -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), diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 64dce3e1738..c9a4df0317a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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 }; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 9c5e3cbc938..e569d1c443a 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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| { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index cedd7926290..07cc8332b84 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -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); // `::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, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f54a5948665..61520e29236 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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, }) diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index dabae6cbc41..50d9a1ebd2c 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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, ) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e5d2c569004..d906c5c05c0 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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, 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, 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)] diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 7936d003f54..7c80315ee19 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -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. diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index 0cc99a7a54e..8257c6ce925 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -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 { - 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, } } diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index bbde0b63cbb..135960a4c11 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -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(..) => (), } } diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index 56badb324c7..823a0235b17 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -31,8 +31,12 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate let mut pred: Vec = 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) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 498fa25836c..98d8f100b27 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -315,11 +315,11 @@ fn extract_for_generics( tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> FxHashSet { - 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, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a86ee12fa99..728453deecf 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -480,19 +480,18 @@ fn clean(&self, cx: &DocContext<'_>) -> WherePredicate { impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option { - 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() diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 98e461fe695..0f995a60c22 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -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 diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 7eeb6a75ea7..0fdb5b8c2a4 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -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(), diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index a450d5f16f8..2c70183d876 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -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; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index e39fb23365a..09577877744 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -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; } diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index c4603418ee3..655b1133cf7 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -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; } -- 2.44.0