From cad8fe90fd61c410ac3e7e97a6be37c96ca66a72 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 21:09:57 +0200 Subject: [PATCH] rename `Predicate` to `PredicateKind`, introduce alias --- .../infer/canonical/query_response.rs | 10 +- src/librustc_infer/infer/combine.rs | 2 +- src/librustc_infer/infer/outlives/mod.rs | 20 ++-- src/librustc_infer/infer/sub.rs | 2 +- src/librustc_infer/traits/util.rs | 60 ++++++------ src/librustc_lint/builtin.rs | 6 +- src/librustc_lint/unused.rs | 2 +- src/librustc_middle/ty/codec.rs | 4 +- src/librustc_middle/ty/mod.rs | 98 ++++++++++--------- src/librustc_middle/ty/print/pretty.rs | 18 ++-- src/librustc_middle/ty/structural_impls.rs | 56 ++++++----- src/librustc_middle/ty/sty.rs | 2 +- .../borrow_check/diagnostics/region_errors.rs | 2 +- .../borrow_check/type_check/mod.rs | 10 +- .../transform/qualify_min_const_fn.rs | 24 ++--- src/librustc_privacy/lib.rs | 8 +- src/librustc_trait_selection/opaque_types.rs | 22 ++--- .../traits/auto_trait.rs | 16 +-- .../traits/error_reporting/mod.rs | 36 +++---- .../traits/error_reporting/suggestions.rs | 2 +- .../traits/fulfill.rs | 18 ++-- src/librustc_trait_selection/traits/mod.rs | 2 +- .../traits/object_safety.rs | 40 ++++---- .../traits/project.rs | 8 +- .../traits/query/type_op/prove_predicate.rs | 4 +- src/librustc_trait_selection/traits/select.rs | 22 ++--- src/librustc_trait_selection/traits/wf.rs | 38 +++---- .../implied_outlives_bounds.rs | 20 ++-- .../normalize_erasing_regions.rs | 18 ++-- src/librustc_traits/type_op.rs | 7 +- src/librustc_typeck/astconv.rs | 4 +- src/librustc_typeck/check/closure.rs | 6 +- src/librustc_typeck/check/coercion.rs | 4 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/dropck.rs | 6 +- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 20 ++-- src/librustc_typeck/check/method/suggest.rs | 10 +- src/librustc_typeck/check/mod.rs | 38 +++---- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/collect.rs | 14 +-- .../constrained_generic_params.rs | 2 +- .../impl_wf_check/min_specialization.rs | 26 ++--- src/librustc_typeck/outlives/explicit.rs | 20 ++-- src/librustc_typeck/outlives/mod.rs | 8 +- src/librustdoc/clean/auto_trait.rs | 6 +- src/librustdoc/clean/mod.rs | 28 +++--- src/librustdoc/clean/simplify.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 2 +- .../clippy/clippy_lints/src/methods/mod.rs | 4 +- .../src/needless_pass_by_value.rs | 2 +- .../clippy/clippy_lints/src/utils/mod.rs | 2 +- 53 files changed, 406 insertions(+), 383 deletions(-) diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index c7a7cf89b4f..67c8265cb11 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -532,12 +532,12 @@ fn query_outlives_constraints_into_obligations<'a>( cause.clone(), param_env, match k1.unpack() { - GenericArgKind::Lifetime(r1) => ty::Predicate::RegionOutlives( + GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives( ty::Binder::bind(ty::OutlivesPredicate(r1, r2)), ), - GenericArgKind::Type(t1) => { - ty::Predicate::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate(t1, r2))) - } + GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind( + ty::OutlivesPredicate(t1, r2), + )), GenericArgKind::Const(..) => { // Consts cannot outlive one another, so we don't expect to // ecounter this branch. @@ -664,7 +664,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::Predicate::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate( + predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate( sup, sub, ))), recursion_depth: 0, diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index 3467457b449..2a188b21205 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -307,7 +307,7 @@ pub fn instantiate( self.obligations.push(Obligation::new( self.trace.cause.clone(), self.param_env, - ty::Predicate::WellFormed(b_ty), + ty::PredicateKind::WellFormed(b_ty), )); } diff --git a/src/librustc_infer/infer/outlives/mod.rs b/src/librustc_infer/infer/outlives/mod.rs index 289457e2bd0..e423137da8f 100644 --- a/src/librustc_infer/infer/outlives/mod.rs +++ b/src/librustc_infer/infer/outlives/mod.rs @@ -12,16 +12,16 @@ pub fn explicit_outlives_bounds<'tcx>( ) -> impl Iterator> + 'tcx { debug!("explicit_outlives_bounds()"); param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate { - ty::Predicate::Projection(..) - | ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, - ty::Predicate::RegionOutlives(ref data) => data + 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)), }) diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 1ec67ef2efa..22231488b7b 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::Predicate::Subtype(ty::Binder::dummy(ty::SubtypePredicate { + ty::PredicateKind::Subtype(ty::Binder::dummy(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 ee903b676ba..400fe4d1321 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -11,39 +11,39 @@ pub fn anonymize_predicate<'tcx>( pred: &ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { match *pred { - ty::Predicate::Trait(ref data, constness) => { - ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data), constness) + ty::PredicateKind::Trait(ref data, constness) => { + ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness) } - ty::Predicate::RegionOutlives(ref data) => { - ty::Predicate::RegionOutlives(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::RegionOutlives(ref data) => { + ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::TypeOutlives(ref data) => { - ty::Predicate::TypeOutlives(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::Projection(ref data) => { - ty::Predicate::Projection(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Projection(ref data) => { + ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::WellFormed(data) => ty::Predicate::WellFormed(data), + ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data), - ty::Predicate::ObjectSafe(data) => ty::Predicate::ObjectSafe(data), + ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) } - ty::Predicate::Subtype(ref data) => { - ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Subtype(ref data) => { + ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { - ty::Predicate::ConstEvaluatable(def_id, substs) + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) } - ty::Predicate::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2), + ty::PredicateKind::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2), } } @@ -146,7 +146,7 @@ pub fn filter_to_traits(self) -> FilterToTraits { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; match obligation.predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -167,36 +167,36 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { self.stack.extend(obligations); } - ty::Predicate::WellFormed(..) => { + ty::PredicateKind::WellFormed(..) => { // Currently, we do not elaborate WF predicates, // although we easily could. } - ty::Predicate::ObjectSafe(..) => { + ty::PredicateKind::ObjectSafe(..) => { // Currently, we do not elaborate object-safe // predicates. } - ty::Predicate::Subtype(..) => { + ty::PredicateKind::Subtype(..) => { // Currently, we do not "elaborate" predicates like `X <: Y`, // though conceivably we might. } - ty::Predicate::Projection(..) => { + ty::PredicateKind::Projection(..) => { // Nothing to elaborate in a projection predicate. } - ty::Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { // Nothing to elaborate when waiting for a closure's kind to be inferred. } - ty::Predicate::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Currently, we do not elaborate const-evaluatable // predicates. } - ty::Predicate::ConstEquate(..) => { + ty::PredicateKind::ConstEquate(..) => { // Currently, we do not elaborate const-equate // predicates. } - ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { // Nothing to elaborate from `'a: 'b`. } - ty::Predicate::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(ref data) => { // 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 @@ -228,7 +228,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { if r.is_late_bound() { None } else { - Some(ty::Predicate::RegionOutlives(ty::Binder::dummy( + Some(ty::PredicateKind::RegionOutlives(ty::Binder::dummy( ty::OutlivesPredicate(r, r_min), ))) } @@ -236,7 +236,7 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { Component::Param(p) => { let ty = tcx.mk_ty_param(p.index, p.name); - Some(ty::Predicate::TypeOutlives(ty::Binder::dummy( + Some(ty::PredicateKind::TypeOutlives(ty::Binder::dummy( ty::OutlivesPredicate(ty, r_min), ))) } @@ -317,7 +317,7 @@ impl<'tcx, I: Iterator>> Iterator for FilterToT fn next(&mut self) -> Option> { while let Some(obligation) = self.base_iterator.next() { - if let ty::Predicate::Trait(data, _) = obligation.predicate { + if let ty::PredicateKind::Trait(data, _) = obligation.predicate { return Some(data.to_poly_trait_ref()); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index bca91fb7b5d..6e1258e25bb 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<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'tcx>) { use rustc_middle::ty::fold::TypeFoldable; - use rustc_middle::ty::Predicate::*; + use rustc_middle::ty::PredicateKind::*; if cx.tcx.features().trivial_bounds { let def_id = cx.tcx.hir().local_def_id(item.hir_id); @@ -1498,7 +1498,7 @@ fn lifetimes_outliving_lifetime<'tcx>( inferred_outlives .iter() .filter_map(|(pred, _)| match pred { - ty::Predicate::RegionOutlives(outlives) => { + ty::PredicateKind::RegionOutlives(outlives) => { let outlives = outlives.skip_binder(); match outlives.0 { ty::ReEarlyBound(ebr) if ebr.index == index => Some(outlives.1), @@ -1517,7 +1517,7 @@ fn lifetimes_outliving_type<'tcx>( inferred_outlives .iter() .filter_map(|(pred, _)| match pred { - ty::Predicate::TypeOutlives(outlives) => { + ty::PredicateKind::TypeOutlives(outlives) => { let outlives = outlives.skip_binder(); outlives.0.is_param(index).then_some(outlives.1) } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index c24079a6e4b..19146f68fce 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -146,7 +146,7 @@ fn check_must_use_ty<'tcx>( ty::Opaque(def, _) => { let mut has_emitted = false; for (predicate, _) in cx.tcx.predicates_of(def).predicates { - if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { let trait_ref = poly_trait_predicate.skip_binder().trait_ref; let def_id = trait_ref.def_id; let descr_pre = diff --git a/src/librustc_middle/ty/codec.rs b/src/librustc_middle/ty/codec.rs index cbbc937ed7d..7ebeb6243be 100644 --- a/src/librustc_middle/ty/codec.rs +++ b/src/librustc_middle/ty/codec.rs @@ -201,9 +201,9 @@ pub fn decode_spanned_predicates( assert!(pos >= SHORTHAND_OFFSET); let shorthand = pos - SHORTHAND_OFFSET; - decoder.with_position(shorthand, ty::Predicate::decode) + decoder.with_position(shorthand, ty::PredicateKind::decode) } else { - ty::Predicate::decode(decoder) + ty::PredicateKind::decode(decoder) }?; Ok((predicate, Decodable::decode(decoder)?)) }) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 36bc44f5e50..e3aeb242dc0 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1016,9 +1016,11 @@ pub fn instantiate_supertrait( } } +pub type Predicate<'tcx> = PredicateKind<'tcx>; + #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] #[derive(HashStable, TypeFoldable)] -pub enum Predicate<'tcx> { +pub enum PredicateKind<'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. @@ -1079,7 +1081,7 @@ fn as_ref(&self) -> &Predicate<'tcx> { } } -impl<'tcx> Predicate<'tcx> { +impl<'tcx> PredicateKind<'tcx> { /// Performs a substitution suitable for going from a /// poly-trait-ref to supertraits that must hold if that /// poly-trait-ref holds. This is slightly different from a normal @@ -1152,31 +1154,31 @@ pub fn subst_supertrait( let substs = &trait_ref.skip_binder().substs; match *self { - Predicate::Trait(ref binder, constness) => { - Predicate::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) + PredicateKind::Trait(ref binder, constness) => { + PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) } - Predicate::Subtype(ref binder) => { - Predicate::Subtype(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::Subtype(ref binder) => { + PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::RegionOutlives(ref binder) => { - Predicate::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::RegionOutlives(ref binder) => { + PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::TypeOutlives(ref binder) => { - Predicate::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::TypeOutlives(ref binder) => { + PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::Projection(ref binder) => { - Predicate::Projection(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::Projection(ref binder) => { + PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::WellFormed(data) => Predicate::WellFormed(data.subst(tcx, substs)), - Predicate::ObjectSafe(trait_def_id) => Predicate::ObjectSafe(trait_def_id), - Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { - Predicate::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind) + PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)), + PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id), + PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind) } - Predicate::ConstEvaluatable(def_id, const_substs) => { - Predicate::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)) + PredicateKind::ConstEvaluatable(def_id, const_substs) => { + PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)) } - Predicate::ConstEquate(c1, c2) => { - Predicate::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) + PredicateKind::ConstEquate(c1, c2) => { + PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) } } } @@ -1298,7 +1300,7 @@ pub trait ToPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, ) @@ -1307,7 +1309,7 @@ fn to_predicate(&self) -> Predicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }), self.constness, ) @@ -1316,62 +1318,62 @@ fn to_predicate(&self) -> Predicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(self.value.to_poly_trait_predicate(), self.constness) + ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(self.value.to_poly_trait_predicate(), self.constness) + ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::RegionOutlives(*self) + PredicateKind::RegionOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::TypeOutlives(*self) + PredicateKind::TypeOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::Projection(*self) + PredicateKind::Projection(*self) } } -impl<'tcx> Predicate<'tcx> { +impl<'tcx> PredicateKind<'tcx> { pub fn to_opt_poly_trait_ref(&self) -> Option> { match *self { - Predicate::Trait(ref t, _) => Some(t.to_poly_trait_ref()), - Predicate::Projection(..) - | Predicate::Subtype(..) - | Predicate::RegionOutlives(..) - | Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::TypeOutlives(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => None, + PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), + PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::TypeOutlives(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) => None, } } pub fn to_opt_type_outlives(&self) -> Option> { match *self { - Predicate::TypeOutlives(data) => Some(data), - Predicate::Trait(..) - | Predicate::Projection(..) - | Predicate::Subtype(..) - | Predicate::RegionOutlives(..) - | Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => None, + PredicateKind::TypeOutlives(data) => Some(data), + PredicateKind::Trait(..) + | PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) => None, } } } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 2502a4a13a8..c224c937b07 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -2032,28 +2032,28 @@ pub fn print_only_trait_path(self) -> ty::Binder { match *self { - ty::Predicate::Trait(ref data, constness) => { + ty::PredicateKind::Trait(ref data, constness) => { if let hir::Constness::Const = constness { p!(write("const ")); } p!(print(data)) } - ty::Predicate::Subtype(ref predicate) => p!(print(predicate)), - ty::Predicate::RegionOutlives(ref predicate) => p!(print(predicate)), - ty::Predicate::TypeOutlives(ref predicate) => p!(print(predicate)), - ty::Predicate::Projection(ref predicate) => p!(print(predicate)), - ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")), - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::Subtype(ref predicate) => p!(print(predicate)), + ty::PredicateKind::RegionOutlives(ref predicate) => p!(print(predicate)), + ty::PredicateKind::TypeOutlives(ref predicate) => p!(print(predicate)), + ty::PredicateKind::Projection(ref predicate) => p!(print(predicate)), + ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")), + ty::PredicateKind::ObjectSafe(trait_def_id) => { p!(write("the trait `"), print_def_path(trait_def_id, &[]), write("` is object-safe")) } - ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => { + 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::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { p!(write("the constant `"), print_value_path(def_id, substs), write("` can be evaluated")) diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index c23a351ac51..54f34a3e078 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -219,25 +219,27 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -impl fmt::Debug for ty::Predicate<'tcx> { +impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ty::Predicate::Trait(ref a, constness) => { + ty::PredicateKind::Trait(ref a, constness) => { if let hir::Constness::Const = constness { write!(f, "const ")?; } a.fmt(f) } - ty::Predicate::Subtype(ref pair) => pair.fmt(f), - ty::Predicate::RegionOutlives(ref pair) => pair.fmt(f), - ty::Predicate::TypeOutlives(ref pair) => pair.fmt(f), - ty::Predicate::Projection(ref pair) => pair.fmt(f), - ty::Predicate::WellFormed(ty) => write!(f, "WellFormed({:?})", ty), - ty::Predicate::ObjectSafe(trait_def_id) => write!(f, "ObjectSafe({:?})", trait_def_id), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + 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(ty) => write!(f, "WellFormed({:?})", ty), + ty::PredicateKind::ObjectSafe(trait_def_id) => { + write!(f, "ObjectSafe({:?})", trait_def_id) + } + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) } ty::Predicate::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), @@ -471,30 +473,32 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { type Lifted = ty::Predicate<'tcx>; fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option { match *self { - ty::Predicate::Trait(ref binder, constness) => { - tcx.lift(binder).map(|binder| ty::Predicate::Trait(binder, constness)) + ty::PredicateKind::Trait(ref binder, constness) => { + tcx.lift(binder).map(|binder| ty::PredicateKind::Trait(binder, constness)) + } + ty::PredicateKind::Subtype(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Subtype) } - ty::Predicate::Subtype(ref binder) => tcx.lift(binder).map(ty::Predicate::Subtype), - ty::Predicate::RegionOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::RegionOutlives) + ty::PredicateKind::RegionOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::RegionOutlives) } - ty::Predicate::TypeOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::TypeOutlives) + ty::PredicateKind::TypeOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::TypeOutlives) } - ty::Predicate::Projection(ref binder) => { - tcx.lift(binder).map(ty::Predicate::Projection) + ty::PredicateKind::Projection(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Projection) } - ty::Predicate::WellFormed(ty) => tcx.lift(&ty).map(ty::Predicate::WellFormed), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateKind::WellFormed), + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { tcx.lift(&closure_substs).map(|closure_substs| { - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) }) } - ty::Predicate::ObjectSafe(trait_def_id) => { - Some(ty::Predicate::ObjectSafe(trait_def_id)) + ty::PredicateKind::ObjectSafe(trait_def_id) => { + Some(ty::PredicateKind::ObjectSafe(trait_def_id)) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { - tcx.lift(&substs).map(|substs| ty::Predicate::ConstEvaluatable(def_id, substs)) + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs)) } ty::Predicate::ConstEquate(c1, c2) => { tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::Predicate::ConstEquate(c1, c2)) diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 2ad673b2c19..8962b243911 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -615,7 +615,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicat Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate() } ExistentialPredicate::Projection(p) => { - ty::Predicate::Projection(Binder(p.with_self_ty(tcx, self_ty))) + ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty))) } ExistentialPredicate::AutoTrait(did) => { let trait_ref = diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index 98c0542f9c0..d7ea88725ed 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -576,7 +576,7 @@ fn add_static_impl_trait_suggestion( let mut found = false; for predicate in bounds.predicates { - if let ty::Predicate::TypeOutlives(binder) = predicate { + if let ty::PredicateKind::TypeOutlives(binder) = predicate { if let ty::OutlivesPredicate(_, ty::RegionKind::ReStatic) = binder.skip_binder() { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 08aa4340107..d3b1b92bdcd 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1016,7 +1016,7 @@ fn check_user_type_annotations(&mut self) { } self.prove_predicate( - ty::Predicate::WellFormed(inferred_ty), + ty::PredicateKind::WellFormed(inferred_ty), Locations::All(span), ConstraintCategory::TypeAnnotation, ); @@ -1268,7 +1268,7 @@ fn eq_opaque_type_and_type( obligations.obligations.push(traits::Obligation::new( ObligationCause::dummy(), param_env, - ty::Predicate::WellFormed(revealed_ty), + ty::PredicateKind::WellFormed(revealed_ty), )); obligations.add( infcx @@ -1612,7 +1612,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::Predicate::WellFormed(ty)), + sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty)), term_location.to_locations(), ConstraintCategory::Boring, ); @@ -2017,7 +2017,7 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L traits::ObligationCauseCode::RepeatVec(should_suggest), ), self.param_env, - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::bind(ty::TraitPredicate { trait_ref: ty::TraitRef::new( self.tcx().require_lang_item( @@ -2686,7 +2686,7 @@ fn prove_trait_ref( category: ConstraintCategory, ) { self.prove_predicates( - Some(ty::Predicate::Trait( + Some(ty::PredicateKind::Trait( trait_ref.to_poly_trait_ref().to_poly_trait_predicate(), 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 07502848893..7fdf9133dd4 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::mir::*; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, adjustment::PointerCast, Predicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use std::borrow::Cow; @@ -24,20 +24,22 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { match predicate { - Predicate::RegionOutlives(_) - | Predicate::TypeOutlives(_) - | Predicate::WellFormed(_) - | Predicate::Projection(_) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => continue, - Predicate::ObjectSafe(_) => { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => continue, + ty::PredicateKind::ObjectSafe(_) => { bug!("object safe predicate on function: {:#?}", predicate) } - Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { bug!("closure kind predicate on function: {:#?}", predicate) } - Predicate::Subtype(_) => bug!("subtype predicate on function: {:#?}", predicate), - Predicate::Trait(pred, constness) => { + ty::PredicateKind::Subtype(_) => { + bug!("subtype predicate on function: {:#?}", predicate) + } + ty::PredicateKind::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 b474b23ac4f..64a2a9055f3 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -91,13 +91,13 @@ fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool let ty::GenericPredicates { parent: _, predicates } = predicates; for (predicate, _span) in predicates { match predicate { - ty::Predicate::Trait(poly_predicate, _) => { + ty::PredicateKind::Trait(poly_predicate, _) => { let ty::TraitPredicate { trait_ref } = *poly_predicate.skip_binder(); if self.visit_trait(trait_ref) { return true; } } - ty::Predicate::Projection(poly_predicate) => { + ty::PredicateKind::Projection(poly_predicate) => { let ty::ProjectionPredicate { projection_ty, ty } = *poly_predicate.skip_binder(); if ty.visit_with(self) { @@ -107,13 +107,13 @@ fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool return true; } } - ty::Predicate::TypeOutlives(poly_predicate) => { + ty::PredicateKind::TypeOutlives(poly_predicate) => { let ty::OutlivesPredicate(ty, _region) = *poly_predicate.skip_binder(); if ty.visit_with(self) { return true; } } - ty::Predicate::RegionOutlives(..) => {} + ty::PredicateKind::RegionOutlives(..) => {} _ => bug!("unexpected predicate: {:?}", predicate), } } diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 396965fcfb8..472f93201c3 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -1168,7 +1168,7 @@ fn fold_opaque_ty( debug!("instantiate_opaque_types: ty_var={:?}", ty_var); for predicate in &bounds.predicates { - if let ty::Predicate::Projection(projection) = &predicate { + if let ty::PredicateKind::Projection(projection) = &predicate { if projection.skip_binder().ty.references_error() { // No point on adding these obligations since there's a type error involved. return ty_var; @@ -1270,16 +1270,16 @@ pub fn may_define_opaque_type( .filter_map(|obligation| { debug!("required_region_bounds(obligation={:?})", obligation); match obligation.predicate { - ty::Predicate::Projection(..) - | ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, - ty::Predicate::TypeOutlives(predicate) => { + 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::TypeOutlives(predicate) => { // 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 e19ddcd9e5e..af9623c4998 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -341,7 +341,7 @@ fn evaluate_predicates( already_visited.remove(&pred); self.add_user_pred( &mut user_computed_preds, - ty::Predicate::Trait(pred, hir::Constness::NotConst), + ty::PredicateKind::Trait(pred, hir::Constness::NotConst), ); predicates.push_back(pred); } else { @@ -411,8 +411,10 @@ fn add_user_pred<'c>( ) { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { - if let (&ty::Predicate::Trait(new_trait, _), ty::Predicate::Trait(old_trait, _)) = - (&new_pred, old_pred) + if let ( + &ty::PredicateKind::Trait(new_trait, _), + ty::PredicateKind::Trait(old_trait, _), + ) = (&new_pred, old_pred) { if new_trait.def_id() == old_trait.def_id() { let new_substs = new_trait.skip_binder().trait_ref.substs; @@ -631,7 +633,7 @@ fn evaluate_nested_obligations( // We check this by calling is_of_param on the relevant types // from the various possible predicates match &predicate { - &ty::Predicate::Trait(p, _) => { + &ty::PredicateKind::Trait(p, _) => { if self.is_param_no_infer(p.skip_binder().trait_ref.substs) && !only_projections && is_new_pred @@ -640,7 +642,7 @@ fn evaluate_nested_obligations( } predicates.push_back(p); } - &ty::Predicate::Projection(p) => { + &ty::PredicateKind::Projection(p) => { debug!( "evaluate_nested_obligations: examining projection predicate {:?}", predicate @@ -765,12 +767,12 @@ fn evaluate_nested_obligations( } } } - &ty::Predicate::RegionOutlives(ref binder) => { + &ty::PredicateKind::RegionOutlives(ref binder) => { if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() { return false; } } - &ty::Predicate::TypeOutlives(ref binder) => { + &ty::PredicateKind::TypeOutlives(ref binder) => { match ( binder.no_bound_vars(), binder.map_bound_ref(|pred| pred.0).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 139b8600722..ac119a0c3d8 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -253,7 +253,7 @@ fn report_selection_error( return; } match obligation.predicate { - ty::Predicate::Trait(ref trait_predicate, _) => { + ty::PredicateKind::Trait(ref trait_predicate, _) => { let trait_predicate = self.resolve_vars_if_possible(trait_predicate); if self.tcx.sess.has_errors() && trait_predicate.references_error() { @@ -468,7 +468,7 @@ fn report_selection_error( trait_pred }); let unit_obligation = Obligation { - predicate: ty::Predicate::Trait( + predicate: ty::PredicateKind::Trait( predicate, hir::Constness::NotConst, ), @@ -489,14 +489,14 @@ fn report_selection_error( err } - ty::Predicate::Subtype(ref predicate) => { + ty::PredicateKind::Subtype(ref predicate) => { // Errors for Subtype predicates show up as // `FulfillmentErrorCode::CodeSubtypeError`, // not selection error. span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate) } - ty::Predicate::RegionOutlives(ref predicate) => { + ty::PredicateKind::RegionOutlives(ref predicate) => { let predicate = self.resolve_vars_if_possible(predicate); let err = self .region_outlives_predicate(&obligation.cause, &predicate) @@ -512,7 +512,7 @@ fn report_selection_error( ) } - ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => { + ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => { let predicate = self.resolve_vars_if_possible(&obligation.predicate); struct_span_err!( self.tcx.sess, @@ -523,12 +523,12 @@ fn report_selection_error( ) } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::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::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::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( @@ -587,7 +587,7 @@ fn report_selection_error( return; } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { if !self.tcx.sess.opts.debugging_opts.chalk { // WF predicates cannot themselves make // errors. They can only block due to @@ -605,7 +605,7 @@ fn report_selection_error( } } - ty::Predicate::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Errors for `ConstEvaluatable` predicates show up as // `SelectionError::ConstEvalFailure`, // not `Unimplemented`. @@ -1047,7 +1047,9 @@ fn error_implies(&self, cond: &ty::Predicate<'tcx>, error: &ty::Predicate<'tcx>) } let (cond, error) = match (cond, error) { - (&ty::Predicate::Trait(..), &ty::Predicate::Trait(ref error, _)) => (cond, error), + (&ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(ref error, _)) => { + (cond, error) + } _ => { // FIXME: make this work in other cases too. return false; @@ -1055,7 +1057,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::Predicate::Trait(implication, _) = obligation.predicate { + if let ty::PredicateKind::Trait(implication, _) = obligation.predicate { let error = error.to_poly_trait_ref(); let implication = implication.to_poly_trait_ref(); // FIXME: I'm just not taking associated types at all here. @@ -1135,7 +1137,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::Predicate::Projection(ref data) = predicate { + if let ty::PredicateKind::Projection(ref data) = predicate { let mut selcx = SelectionContext::new(self); let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1416,7 +1418,7 @@ fn maybe_report_ambiguity( } let mut err = match predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { let trait_ref = data.to_poly_trait_ref(); let self_ty = trait_ref.self_ty(); debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref); @@ -1515,7 +1517,7 @@ fn maybe_report_ambiguity( err } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { // Same hacky approach as above to avoid deluging user // with error messages. if ty.references_error() || self.tcx.sess.has_errors() { @@ -1524,7 +1526,7 @@ fn maybe_report_ambiguity( self.need_type_info_err(body_id, span, ty, ErrorCode::E0282) } - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::Subtype(ref data) => { if data.references_error() || self.tcx.sess.has_errors() { // no need to overload user in such cases return; @@ -1534,7 +1536,7 @@ fn maybe_report_ambiguity( assert!(a.is_ty_var() && b.is_ty_var()); self.need_type_info_err(body_id, span, a, ErrorCode::E0282) } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let trait_ref = data.to_poly_trait_ref(self.tcx); let self_ty = trait_ref.self_ty(); let ty = data.skip_binder().ty; @@ -1658,7 +1660,7 @@ fn suggest_unsized_bound_if_applicable( obligation: &PredicateObligation<'tcx>, ) { if let ( - ty::Predicate::Trait(pred, _), + ty::PredicateKind::Trait(pred, _), ObligationCauseCode::BindingObligation(item_def_id, span), ) = (&obligation.predicate, &obligation.cause.code) { diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index b8771d59dd4..5baaf838caa 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -1238,7 +1238,7 @@ fn maybe_note_obligation_cause_for_async_await( // 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 { - ty::Predicate::Trait(p, _) => { + ty::PredicateKind::Trait(p, _) => { (Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty())) } _ => (None, None), diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 98f6ac0e547..0497dec4029 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -323,7 +323,7 @@ fn process_obligation( let infcx = self.selcx.infcx(); match obligation.predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { let trait_obligation = obligation.with(*data); if data.is_global() { @@ -378,14 +378,14 @@ fn process_obligation( } } - ty::Predicate::RegionOutlives(ref binder) => { + ty::PredicateKind::RegionOutlives(ref binder) => { match infcx.region_outlives_predicate(&obligation.cause, binder) { Ok(()) => ProcessResult::Changed(vec![]), Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)), } } - ty::Predicate::TypeOutlives(ref binder) => { + ty::PredicateKind::TypeOutlives(ref binder) => { // Check if there are higher-ranked vars. match binder.no_bound_vars() { // If there are, inspect the underlying type further. @@ -429,7 +429,7 @@ fn process_obligation( } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(*data); match project::poly_project_and_unify_type(self.selcx, &project_obligation) { Ok(None) => { @@ -443,7 +443,7 @@ fn process_obligation( } } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if !self.selcx.tcx().is_object_safe(trait_def_id) { ProcessResult::Error(CodeSelectionError(Unimplemented)) } else { @@ -451,7 +451,7 @@ fn process_obligation( } } - ty::Predicate::ClosureKind(_, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.selcx.infcx().closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -464,7 +464,7 @@ fn process_obligation( } } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { match wf::obligations( self.selcx.infcx(), obligation.param_env, @@ -481,7 +481,7 @@ fn process_obligation( } } - ty::Predicate::Subtype(ref subtype) => { + ty::PredicateKind::Subtype(ref subtype) => { match self.selcx.infcx().subtype_predicate( &obligation.cause, obligation.param_env, @@ -510,7 +510,7 @@ fn process_obligation( } } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.selcx.infcx().const_eval_resolve( obligation.param_env, def_id, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 9592f93ce2e..99d434c5c92 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -334,7 +334,7 @@ pub fn normalize_param_env_or_error<'tcx>( // TypeOutlives predicates - these are normally used by regionck. let outlives_predicates: Vec<_> = predicates .drain_filter(|predicate| match predicate { - ty::Predicate::TypeOutlives(..) => true, + ty::PredicateKind::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 1bfcacd6ccd..bb727055d03 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -246,7 +246,7 @@ fn predicates_reference_self( .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp)) .filter_map(|(predicate, &sp)| { match predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) @@ -254,7 +254,7 @@ fn predicates_reference_self( None } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::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 @@ -276,14 +276,14 @@ fn predicates_reference_self( None } } - ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => 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, } }) .collect() @@ -305,18 +305,18 @@ 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 { - ty::Predicate::Trait(ref trait_pred, _) => { + ty::PredicateKind::Trait(ref trait_pred, _) => { trait_pred.def_id() == sized_def_id && trait_pred.skip_binder().self_ty().is_param(0) } - ty::Predicate::Projection(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => false, + 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, }) } diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index c4cb72fa08c..54b064359dc 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -671,7 +671,9 @@ fn prune_cache_value_obligations<'a, 'tcx>( // indirect obligations (e.g., we project to `?0`, // but we have `T: Foo` and `?1: Bar`). - ty::Predicate::Projection(ref data) => infcx.unresolved_type_vars(&data.ty()).is_some(), + ty::PredicateKind::Projection(ref data) => { + infcx.unresolved_type_vars(&data.ty()).is_some() + } // We are only interested in `T: Foo` predicates, whre // `U` references one of `unresolved_type_vars`. =) @@ -928,7 +930,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::Predicate::Projection(data) = predicate { + if let ty::PredicateKind::Projection(data) = predicate { let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; let is_match = same_def_id @@ -1164,7 +1166,7 @@ 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 { - ty::Predicate::Projection(data) => { + ty::PredicateKind::Projection(data) => { if data.projection_def_id() == obligation.predicate.item_def_id { Some(data) } else { 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 981745af805..c0470084072 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 @@ -1,6 +1,6 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse}; use crate::traits::query::Fallible; -use rustc_middle::ty::{ParamEnvAnd, Predicate, TyCtxt}; +use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt}; pub use rustc_middle::traits::query::type_op::ProvePredicate; @@ -15,7 +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 Predicate::Trait(trait_ref, _) = key.value.predicate { + if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) { diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 70c6cbef102..02da6033a00 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -414,13 +414,13 @@ fn evaluate_predicate_recursively<'o>( } match obligation.predicate { - ty::Predicate::Trait(ref t, _) => { + ty::PredicateKind::Trait(ref t, _) => { debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(*t); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } - ty::Predicate::Subtype(ref p) => { + ty::PredicateKind::Subtype(ref p) => { // Does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { Some(Ok(InferOk { mut obligations, .. })) => { @@ -435,7 +435,7 @@ fn evaluate_predicate_recursively<'o>( } } - ty::Predicate::WellFormed(ty) => match wf::obligations( + ty::PredicateKind::WellFormed(ty) => match wf::obligations( self.infcx, obligation.param_env, obligation.cause.body_id, @@ -449,12 +449,12 @@ fn evaluate_predicate_recursively<'o>( None => Ok(EvaluatedToAmbig), }, - ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => { // We do not consider region relationships when evaluating trait matches. Ok(EvaluatedToOkModuloRegions) } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if self.tcx().is_object_safe(trait_def_id) { Ok(EvaluatedToOk) } else { @@ -462,7 +462,7 @@ fn evaluate_predicate_recursively<'o>( } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(*data); match project::poly_project_and_unify_type(self, &project_obligation) { Ok(Some(mut subobligations)) => { @@ -483,7 +483,7 @@ fn evaluate_predicate_recursively<'o>( } } - ty::Predicate::ClosureKind(_, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.infcx.closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -496,7 +496,7 @@ fn evaluate_predicate_recursively<'o>( } } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.tcx().const_eval_resolve( obligation.param_env, def_id, @@ -676,7 +676,7 @@ fn check_evaluation_cycle( // if the regions match exactly. let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth); let cycle = cycle.map(|stack| { - ty::Predicate::Trait(stack.obligation.predicate, hir::Constness::NotConst) + ty::PredicateKind::Trait(stack.obligation.predicate, hir::Constness::NotConst) }); if self.coinductive_match(cycle) { debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref); @@ -792,7 +792,7 @@ pub fn coinductive_match(&mut self, cycle: I) -> bool fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { let result = match predicate { - ty::Predicate::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), + ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; debug!("coinductive_predicate({:?}) = {:?}", predicate, result); @@ -2921,7 +2921,7 @@ fn confirm_closure_candidate( obligations.push(Obligation::new( obligation.cause.clone(), obligation.param_env, - ty::Predicate::ClosureKind(closure_def_id, substs, kind), + ty::PredicateKind::ClosureKind(closure_def_id, substs, kind), )); } diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 4d3bbfa77c3..b1b50eb2331 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -73,28 +73,28 @@ pub fn predicate_obligations<'a, 'tcx>( // (*) ok to skip binders, because wf code is prepared for it match *predicate { - ty::Predicate::Trait(ref t, _) => { + ty::PredicateKind::Trait(ref t, _) => { wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*) } - ty::Predicate::RegionOutlives(..) => {} - ty::Predicate::TypeOutlives(ref t) => { + ty::PredicateKind::RegionOutlives(..) => {} + ty::PredicateKind::TypeOutlives(ref t) => { wf.compute(t.skip_binder().0); } - ty::Predicate::Projection(ref t) => { + ty::PredicateKind::Projection(ref t) => { let t = t.skip_binder(); // (*) wf.compute_projection(t.projection_ty); wf.compute(t.ty); } - ty::Predicate::WellFormed(t) => { + ty::PredicateKind::WellFormed(t) => { wf.compute(t); } - ty::Predicate::ObjectSafe(_) => {} - ty::Predicate::ClosureKind(..) => {} - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::ObjectSafe(_) => {} + ty::PredicateKind::ClosureKind(..) => {} + ty::PredicateKind::Subtype(ref data) => { wf.compute(data.skip_binder().a); // (*) wf.compute(data.skip_binder().b); // (*) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { let obligations = wf.nominal_obligations(def_id, substs); wf.out.extend(obligations); @@ -171,7 +171,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( _ => impl_item_ref.span, }; match pred { - ty::Predicate::Projection(proj) => { + ty::PredicateKind::Projection(proj) => { // The obligation comes not from the current `impl` nor the `trait` being // implemented, but rather from a "second order" obligation, like in // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`. @@ -194,7 +194,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } } } - ty::Predicate::Trait(pred, _) => { + ty::PredicateKind::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); @@ -276,7 +276,9 @@ fn compute_trait_ref(&mut self, trait_ref: &ty::TraitRef<'tcx>, elaborate: Elabo } self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map( - |ty| traits::Obligation::new(cause.clone(), param_env, ty::Predicate::WellFormed(ty)), + |ty| { + traits::Obligation::new(cause.clone(), param_env, ty::PredicateKind::WellFormed(ty)) + }, )); } @@ -305,7 +307,7 @@ fn compute_array_len(&mut self, constant: ty::Const<'tcx>) { let obligations = self.nominal_obligations(def_id, substs); self.out.extend(obligations); - let predicate = ty::Predicate::ConstEvaluatable(def_id, substs); + let predicate = ty::PredicateKind::ConstEvaluatable(def_id, substs); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -411,9 +413,9 @@ fn compute(&mut self, ty: Ty<'tcx>) { self.out.push(traits::Obligation::new( cause, param_env, - ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( - rty, r, - ))), + ty::PredicateKind::TypeOutlives(ty::Binder::dummy( + ty::OutlivesPredicate(rty, r), + )), )); } } @@ -502,7 +504,7 @@ fn compute(&mut self, ty: Ty<'tcx>) { traits::Obligation::new( cause.clone(), param_env, - ty::Predicate::ObjectSafe(did), + ty::PredicateKind::ObjectSafe(did), ) })); } @@ -528,7 +530,7 @@ fn compute(&mut self, ty: Ty<'tcx>) { self.out.push(traits::Obligation::new( cause, param_env, - ty::Predicate::WellFormed(ty), + ty::PredicateKind::WellFormed(ty), )); } else { // Yes, resolved, proceed with the result. diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index eaaab87ab74..aed5729b34a 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -95,27 +95,27 @@ fn compute_implied_outlives_bounds<'tcx>( implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); match obligation.predicate { - ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::Projection(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => vec![], + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => vec![], - ty::Predicate::WellFormed(subty) => { + ty::PredicateKind::WellFormed(subty) => { wf_types.push(subty); vec![] } - ty::Predicate::RegionOutlives(ref data) => match data.no_bound_vars() { + ty::PredicateKind::RegionOutlives(ref data) => match data.no_bound_vars() { None => vec![], Some(ty::OutlivesPredicate(r_a, r_b)) => { vec![OutlivesBound::RegionSubRegion(r_b, r_a)] } }, - ty::Predicate::TypeOutlives(ref data) => match data.no_bound_vars() { + ty::PredicateKind::TypeOutlives(ref data) => match data.no_bound_vars() { None => vec![], Some(ty::OutlivesPredicate(ty_a, r_b)) => { let ty_a = infcx.resolve_vars_if_possible(&ty_a); diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index ed30ed5313e..11604cc3187 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -41,14 +41,14 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool { match p { - ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false, - ty::Predicate::Trait(..) - | ty::Predicate::Projection(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => true, + ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false, + 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, } } diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index aeb31c2cb73..58fa927c021 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -7,7 +7,8 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; use rustc_middle::ty::{ - FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, Variance, + self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, + Variance, }; use rustc_span::DUMMY_SP; use rustc_trait_selection::infer::InferCtxtBuilderExt; @@ -140,7 +141,7 @@ fn relate_mir_and_user_ty( self.relate(self_ty, Variance::Invariant, impl_self_ty)?; - self.prove_predicate(Predicate::WellFormed(impl_self_ty)); + self.prove_predicate(ty::PredicateKind::WellFormed(impl_self_ty)); } // In addition to proving the predicates, we have to @@ -154,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(Predicate::WellFormed(ty)); + self.prove_predicate(ty::PredicateKind::WellFormed(ty)); Ok(()) } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6529d784ad4..a697ae7cb87 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1597,7 +1597,7 @@ fn conv_object_ty_poly_trait_ref( obligation.predicate ); match obligation.predicate { - ty::Predicate::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _) => { associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) .in_definition_order() @@ -1605,7 +1605,7 @@ fn conv_object_ty_poly_trait_ref( .map(|item| item.def_id), ); } - ty::Predicate::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { // A `Self` within the original bound will be substituted with a // `trait_object_dummy_self`, so check for that. let references_self = diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 87a6f119acb..6ade48b80c8 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -206,7 +206,7 @@ fn deduce_expectations_from_obligations( obligation.predicate ); - if let ty::Predicate::Projection(ref proj_predicate) = obligation.predicate { + if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate { // Given a Projection predicate, we can potentially infer // the complete signature. self.deduce_sig_from_projection(Some(obligation.cause.span), proj_predicate) @@ -526,7 +526,7 @@ fn check_supplied_sig_against_expectation( all_obligations.push(Obligation::new( cause, self.param_env, - ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( + ty::PredicateKind::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( supplied_ty, closure_body_region, ))), @@ -641,7 +641,7 @@ fn deduce_future_output_from_obligations(&self, expr_def_id: DefId) -> Option, mut target: Ty<'tcx>) -> CoerceRe let obligation = queue.remove(0); debug!("coerce_unsized resolve step: {:?}", obligation); let trait_pred = match obligation.predicate { - ty::Predicate::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => { + ty::PredicateKind::Trait(trait_pred, _) + if traits.contains(&trait_pred.def_id()) => + { if unsize_did == trait_pred.def_id() { let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty(); if let ty::Tuple(..) = unsize_ty.kind { diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 9694ce9450c..550a2362795 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -644,7 +644,7 @@ pub fn check_ref( .unwrap() .def_id; let predicate = - ty::Predicate::Projection(ty::Binder::bind(ty::ProjectionPredicate { + ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate { // `::Output` projection_ty: ty::ProjectionTy { // `T` diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 478a848cf09..51d28f7c57c 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -231,8 +231,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let predicate_matches_closure = |p: &'_ Predicate<'tcx>| { let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); match (predicate, p) { - (Predicate::Trait(a, _), Predicate::Trait(b, _)) => relator.relate(a, b).is_ok(), - (Predicate::Projection(a), Predicate::Projection(b)) => { + (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { + relator.relate(a, b).is_ok() + } + (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { relator.relate(a, b).is_ok() } _ => predicate == p, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index c4805c54a7d..64917bf4c9f 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -575,7 +575,7 @@ fn predicates_require_illegal_sized_bound( traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) .filter_map(|obligation| match obligation.predicate { - ty::Predicate::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { + ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { let span = predicates .predicates .iter() diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index a254aecf07b..135e02d6b5f 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -401,7 +401,7 @@ pub fn lookup_method_in_trait( obligations.push(traits::Obligation::new( cause, self.param_env, - ty::Predicate::WellFormed(method_ty), + ty::PredicateKind::WellFormed(method_ty), )); 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 e21db9035e2..fbe8e7b7675 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -797,21 +797,21 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) { // FIXME: do we want to commit to this behavior for param bounds? let bounds = self.param_env.caller_bounds.iter().filter_map(|predicate| match *predicate { - ty::Predicate::Trait(ref trait_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()), _ => None, } } - ty::Predicate::Subtype(..) - | ty::Predicate::Projection(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => 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, }); 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 cf26c94418e..e0ab25e4922 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -574,7 +574,7 @@ macro_rules! report_function { let mut bound_spans = vec![]; let mut collect_type_param_suggestions = |self_ty: Ty<'_>, parent_pred: &ty::Predicate<'_>, obligation: &str| { - if let (ty::Param(_), ty::Predicate::Trait(p, _)) = + if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = (&self_ty.kind, parent_pred) { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { @@ -628,7 +628,7 @@ macro_rules! report_function { }; let mut format_pred = |pred| { match pred { - ty::Predicate::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { // `::Item = String`. let trait_ref = pred.skip_binder().projection_ty.trait_ref(self.tcx); @@ -646,7 +646,7 @@ macro_rules! report_function { bound_span_label(trait_ref.self_ty(), &obligation, &quiet); Some((obligation, trait_ref.self_ty())) } - ty::Predicate::Trait(poly_trait_ref, _) => { + ty::PredicateKind::Trait(poly_trait_ref, _) => { let p = poly_trait_ref.skip_binder().trait_ref; let self_ty = p.self_ty(); let path = p.print_only_trait_path(); @@ -949,8 +949,8 @@ fn suggest_traits_to_import<'b>( unsatisfied_predicates.iter().all(|(p, _)| match p { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. - ty::Predicate::Trait(t, _) => t.def_id() == info.def_id, - ty::Predicate::Projection(p) => p.item_def_id() == info.def_id, + ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, + ty::PredicateKind::Projection(p) => p.item_def_id() == info.def_id, _ => false, }) && (type_is_local || info.def_id.is_local()) && self diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d72c74e4188..79cb7a7fd0f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2224,7 +2224,7 @@ fn bounds_from_generic_predicates( for (predicate, _) in predicates.predicates { debug!("predicate {:?}", predicate); match predicate { - ty::Predicate::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _) => { let entry = types.entry(trait_predicate.skip_binder().self_ty()).or_default(); let def_id = trait_predicate.skip_binder().def_id(); if Some(def_id) != tcx.lang_items().sized_trait() { @@ -2233,7 +2233,7 @@ fn bounds_from_generic_predicates( entry.push(trait_predicate.skip_binder().def_id()); } } - ty::Predicate::Projection(projection_pred) => { + ty::PredicateKind::Projection(projection_pred) => { projections.push(projection_pred); } _ => {} @@ -2770,7 +2770,7 @@ 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 { - ty::Predicate::Trait(ref data, _) + ty::PredicateKind::Trait(ref data, _) if data.skip_binder().self_ty().is_param(index) => { // HACK(eddyb) should get the original `Span`. @@ -3379,7 +3379,7 @@ pub fn to_const(&self, ast_c: &hir::AnonConst) -> &'tcx ty::Const<'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::Predicate::ConstEvaluatable(def_id, substs), + ty::PredicateKind::ConstEvaluatable(def_id, substs), )); } @@ -3428,7 +3428,7 @@ pub fn register_wf_obligation( self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::Predicate::WellFormed(ty), + ty::PredicateKind::WellFormed(ty), )); } @@ -3858,17 +3858,19 @@ fn obligations_for_self_ty<'b>( .pending_obligations() .into_iter() .filter_map(move |obligation| match obligation.predicate { - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { Some((data.to_poly_trait_ref(self.tcx), obligation)) } - ty::Predicate::Trait(ref data, _) => Some((data.to_poly_trait_ref(), obligation)), - ty::Predicate::Subtype(..) => None, - ty::Predicate::RegionOutlives(..) => None, - ty::Predicate::TypeOutlives(..) => None, - ty::Predicate::WellFormed(..) => None, - ty::Predicate::ObjectSafe(..) => None, - ty::Predicate::ConstEvaluatable(..) => None, - ty::Predicate::ConstEquate(..) => None, + ty::PredicateKind::Trait(ref data, _) => { + Some((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, // N.B., this predicate is created by breaking down a // `ClosureType: FnFoo()` predicate, where // `ClosureType` represents some `Closure`. It can't @@ -3877,7 +3879,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::Predicate::ClosureKind(..) => None, + ty::PredicateKind::ClosureKind(..) => None, }) .filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root)) } @@ -4206,7 +4208,7 @@ fn point_at_arg_instead_of_call_if_possible( continue; } - if let ty::Predicate::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { // Collect the argument position for all arguments that could have caused this // `FulfillmentError`. let mut referenced_in = final_arg_types @@ -4253,7 +4255,7 @@ 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::Predicate::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { // If any of the type arguments in this path segment caused the // `FullfillmentError`, point at its span (#61860). for arg in path @@ -5322,7 +5324,7 @@ fn suggest_missing_await( }; let predicate = - ty::Predicate::Projection(ty::Binder::bind(ty::ProjectionPredicate { + ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate { projection_ty, ty: expected, })); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index b79ac50da8f..cb3ee8d1ded 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -425,7 +425,7 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::Predicate::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs), + ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs), )); } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index fe3028102c6..c39df5df977 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -549,7 +549,9 @@ fn type_param_predicates( icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true)) .into_iter() .filter(|(predicate, _)| match predicate { - ty::Predicate::Trait(ref data, _) => data.skip_binder().self_ty().is_param(index), + ty::PredicateKind::Trait(ref data, _) => { + data.skip_binder().self_ty().is_param(index) + } _ => false, }), ); @@ -994,7 +996,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::Predicate::Trait(bound, _) = pred { + if let ty::PredicateKind::Trait(bound, _) = pred { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -1899,7 +1901,7 @@ fn extend, Span)>>(&mut self, iter: let re_root_empty = tcx.lifetimes.re_root_empty; let predicate = ty::OutlivesPredicate(ty, re_root_empty); predicates.push(( - ty::Predicate::TypeOutlives(ty::Binder::dummy(predicate)), + ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate)), span, )); } @@ -1928,7 +1930,7 @@ fn extend, Span)>>(&mut self, iter: &hir::GenericBound::Outlives(ref lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region)); - predicates.push((ty::Predicate::TypeOutlives(pred), lifetime.span)) + predicates.push((ty::PredicateKind::TypeOutlives(pred), lifetime.span)) } } } @@ -1945,7 +1947,7 @@ fn extend, Span)>>(&mut self, iter: }; let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2)); - (ty::Predicate::RegionOutlives(pred), span) + (ty::PredicateKind::RegionOutlives(pred), span) })) } @@ -2116,7 +2118,7 @@ fn predicates_from_bound<'tcx>( hir::GenericBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); - vec![(ty::Predicate::TypeOutlives(pred), lifetime.span)] + vec![(ty::PredicateKind::TypeOutlives(pred), lifetime.span)] } } } diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 07ff3bc85cc..c1be430b93e 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -180,7 +180,7 @@ pub fn setup_constraining_predicates<'tcx>( changed = false; for j in i..predicates.len() { - if let ty::Predicate::Projection(ref poly_projection) = predicates[j].0 { + if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0 { // Note that we can skip binder here because the impl // trait ref never contains any late-bound regions. let projection = poly_projection.skip_binder(); diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index 919bcc9943d..89d63107a9c 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -204,7 +204,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::Predicate::Projection(proj) = predicate { + if let ty::PredicateKind::Projection(proj) = predicate { let projection_ty = proj.skip_binder().projection_ty; let projected_ty = proj.skip_binder().ty; @@ -374,7 +374,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: &ty::Predicate<'t _ if predicate.is_global() => (), // We allow specializing on explicitly marked traits with no associated // items. - ty::Predicate::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { if !matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::Marker) @@ -402,18 +402,18 @@ fn trait_predicate_kind<'tcx>( predicate: &ty::Predicate<'tcx>, ) -> Option { match predicate { - ty::Predicate::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } - ty::Predicate::Trait(_, hir::Constness::Const) - | ty::Predicate::RegionOutlives(_) - | ty::Predicate::TypeOutlives(_) - | ty::Predicate::Projection(_) - | ty::Predicate::WellFormed(_) - | ty::Predicate::Subtype(_) - | ty::Predicate::ObjectSafe(_) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, + 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, } } diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index 66daf0e7f7d..bc8d25f9538 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -30,7 +30,7 @@ pub fn explicit_predicates_of( // process predicates and convert to `RequiredPredicates` entry, see below for &(predicate, span) in predicates.predicates { match predicate { - ty::Predicate::TypeOutlives(predicate) => { + ty::PredicateKind::TypeOutlives(predicate) => { let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder(); insert_outlives_predicate( tcx, @@ -41,7 +41,7 @@ pub fn explicit_predicates_of( ) } - ty::Predicate::RegionOutlives(predicate) => { + ty::PredicateKind::RegionOutlives(predicate) => { let OutlivesPredicate(ref reg1, ref reg2) = predicate.skip_binder(); insert_outlives_predicate( tcx, @@ -52,14 +52,14 @@ pub fn explicit_predicates_of( ) } - ty::Predicate::Trait(..) - | ty::Predicate::Projection(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => (), + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => (), } } diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index a49d8e5ed0f..d88fda35505 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -31,8 +31,8 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate let mut pred: Vec = predicates .iter() .map(|(out_pred, _)| match out_pred { - ty::Predicate::RegionOutlives(p) => p.to_string(), - ty::Predicate::TypeOutlives(p) => p.to_string(), + ty::PredicateKind::RegionOutlives(p) => p.to_string(), + ty::PredicateKind::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), }) .collect(); @@ -84,13 +84,13 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica let predicates = &*tcx.arena.alloc_from_iter(set.iter().filter_map( |(ty::OutlivesPredicate(kind1, region2), &span)| match kind1.unpack() { GenericArgKind::Type(ty1) => Some(( - ty::Predicate::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate( + ty::PredicateKind::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate( ty1, region2, ))), span, )), GenericArgKind::Lifetime(region1) => Some(( - ty::Predicate::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate( + ty::PredicateKind::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate( region1, region2, ))), span, diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 144c1699a3c..ff05c4e5832 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -316,10 +316,10 @@ fn extract_for_generics( pred: ty::Predicate<'tcx>, ) -> FxHashSet { let regions = match pred { - ty::Predicate::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _) => { tcx.collect_referenced_late_bound_regions(&poly_trait_pred) } - ty::Predicate::Projection(poly_proj_pred) => { + ty::PredicateKind::Projection(poly_proj_pred) => { tcx.collect_referenced_late_bound_regions(&poly_proj_pred) } _ => return FxHashSet::default(), @@ -466,7 +466,7 @@ fn param_env_to_generics( .filter(|p| { !orig_bounds.contains(p) || match p { - ty::Predicate::Trait(pred, _) => pred.def_id() == sized_trait, + ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c130ed3f46d..002af495ff2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -481,20 +481,18 @@ fn clean(&self, cx: &DocContext<'_>) -> WherePredicate { impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option { - use rustc_middle::ty::Predicate; - match *self { - Predicate::Trait(ref pred, _) => Some(pred.clean(cx)), - Predicate::Subtype(ref pred) => Some(pred.clean(cx)), - Predicate::RegionOutlives(ref pred) => pred.clean(cx), - Predicate::TypeOutlives(ref pred) => pred.clean(cx), - Predicate::Projection(ref pred) => Some(pred.clean(cx)), + ty::PredicateKind::Trait(ref pred, _) => Some(pred.clean(cx)), + ty::PredicateKind::Subtype(ref pred) => Some(pred.clean(cx)), + ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::TypeOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::Projection(ref pred) => Some(pred.clean(cx)), - Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => panic!("not user writable"), + ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => panic!("not user writable"), } } } @@ -765,7 +763,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics { if let ty::Param(param) = outlives.skip_binder().0.kind { return Some(param.index); } - } else if let ty::Predicate::Projection(p) = p { + } else if let ty::PredicateKind::Projection(p) = p { if let ty::Param(param) = p.skip_binder().projection_ty.self_ty().kind { projection = Some(p); return Some(param.index); @@ -1663,7 +1661,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type { .filter_map(|predicate| { let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() { tr - } else if let ty::Predicate::TypeOutlives(pred) = *predicate { + } else if let ty::PredicateKind::TypeOutlives(pred) = *predicate { // these should turn up at the end if let Some(r) = pred.skip_binder().1.clean(cx) { regions.push(GenericBound::Outlives(r)); @@ -1684,7 +1682,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type { .predicates .iter() .filter_map(|pred| { - if let ty::Predicate::Projection(proj) = *pred { + if let ty::PredicateKind::Projection(proj) = *pred { let proj = proj.skip_binder(); 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 1404d45ea89..cc91c503461 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -141,7 +141,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::Predicate::Trait(ref pred, _) = *pred { + if let ty::PredicateKind::Trait(ref pred, _) = *pred { if pred.skip_binder().trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { 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 704a95ec0a0..2c2965433fd 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, Predicate::Trait, ToPolyTraitRef}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 626427c15ec..79c21d9bc0a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -18,7 +18,7 @@ use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, Predicate, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, SymbolStr}; @@ -1497,7 +1497,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir:: // one of the associated types must be Self for predicate in cx.tcx.predicates_of(def_id).predicates { match predicate { - (Predicate::Projection(poly_projection_predicate), _) => { + (ty::PredicateKind::Projection(poly_projection_predicate), _) => { let binder = poly_projection_predicate.ty(); let associated_type = binder.skip_binder(); 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 ed48ab54897..8f94f143bae 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 @@ -114,7 +114,7 @@ fn check_fn( let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::Predicate::Trait(poly_trait_ref, _) = obligation.predicate { + if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate { if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() { 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 438a9f42ccd..3f5693d7e68 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo 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::Predicate::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { return true; } -- 2.44.0