diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index d9ef5d88f1c..113e2220d4d 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -9,12 +9,8 @@ pub fn anonymize_predicate<'tcx>( tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { - match *pred.kind() { - ty::PredicateKind::ForAll(binder) => { - let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder)); - tcx.reuse_or_mk_predicate(pred, new) - } - } + let new = tcx.anonymize_late_bound_regions(pred.kind()); + tcx.reuse_or_mk_predicate(pred, new) } struct PredicateSet<'tcx> { diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 9d371503e0a..987cb32d914 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -44,9 +44,9 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> { } impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> { - type Variant = ty::PredicateKind<'tcx>; + type Variant = ty::Binder>; fn variant(&self) -> &Self::Variant { - self.kind() + self.kind_ref() } } @@ -226,9 +226,9 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Predicate<'tcx> { assert!(pos >= SHORTHAND_OFFSET); let shorthand = pos - SHORTHAND_OFFSET; - decoder.with_position(shorthand, ty::PredicateKind::decode) + decoder.with_position(shorthand, ty::Binder::>::decode) } else { - ty::PredicateKind::decode(decoder) + ty::Binder::>::decode(decoder) }?; let predicate = decoder.tcx().mk_predicate(predicate_kind); Ok(predicate) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a355242f5ce..78ff8671d13 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -17,9 +17,9 @@ use crate::ty::query::{self, TyCtxtAt}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts}; use crate::ty::TyKind::*; use crate::ty::{ - self, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, DefIdTree, - ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntVar, - IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind, + self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid, + DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, + IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateAtom, PredicateInner, ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, Visibility, }; @@ -133,7 +133,7 @@ impl<'tcx> CtxtInterners<'tcx> { } #[inline(never)] - fn intern_predicate(&self, kind: PredicateKind<'tcx>) -> &'tcx PredicateInner<'tcx> { + fn intern_predicate(&self, kind: Binder>) -> &'tcx PredicateInner<'tcx> { self.predicate .intern(kind, |kind| { let flags = super::flags::FlagComputation::for_predicate(kind); @@ -1948,8 +1948,8 @@ impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> { } } -impl<'tcx> Borrow> for Interned<'tcx, PredicateInner<'tcx>> { - fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> { +impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { + fn borrow<'a>(&'a self) -> &'a Binder> { &self.0.kind } } @@ -1987,12 +1987,6 @@ impl<'tcx> Borrow> for Interned<'tcx, Const<'tcx>> { } } -impl<'tcx> Borrow> for Interned<'tcx, PredicateKind<'tcx>> { - fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> { - &self.0 - } -} - macro_rules! direct_interners { ($($name:ident: $method:ident($ty:ty),)+) => { $(impl<'tcx> PartialEq for Interned<'tcx, $ty> { @@ -2091,7 +2085,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> { + pub fn mk_predicate(self, kind: Binder>) -> Predicate<'tcx> { let inner = self.interners.intern_predicate(kind); Predicate { inner } } @@ -2100,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn reuse_or_mk_predicate( self, pred: Predicate<'tcx>, - kind: PredicateKind<'tcx>, + kind: Binder>, ) -> Predicate<'tcx> { - if *pred.kind() != kind { self.mk_predicate(kind) } else { pred } + if pred.kind() != kind { self.mk_predicate(kind) } else { pred } } pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> { diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index b7e045534b2..b99587fe734 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -22,7 +22,7 @@ impl FlagComputation { result } - pub fn for_predicate(kind: ty::PredicateKind<'_>) -> FlagComputation { + pub fn for_predicate(kind: ty::Binder>) -> FlagComputation { let mut result = FlagComputation::new(); result.add_predicate_kind(kind); result @@ -204,8 +204,7 @@ impl FlagComputation { } } - fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) { - let ty::PredicateKind::ForAll(binder) = kind; + fn add_predicate_kind(&mut self, binder: ty::Binder>) { self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom)); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 97f8cc0a239..e023195605b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> { #[derive(Debug)] crate struct PredicateInner<'tcx> { - kind: PredicateKind<'tcx>, + kind: Binder>, flags: TypeFlags, /// See the comment for the corresponding field of [TyS]. outer_exclusive_binder: ty::DebruijnIndex, @@ -1061,7 +1061,12 @@ impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { #[inline(always)] - pub fn kind(self) -> &'tcx PredicateKind<'tcx> { + pub fn kind(self) -> Binder> { + self.inner.kind + } + + #[inline(always)] + pub fn kind_ref(&self) -> &Binder> { &self.inner.kind } @@ -1072,7 +1077,7 @@ impl<'tcx> Predicate<'tcx> { /// /// Note that this method panics in case this predicate has unbound variables. pub fn skip_binders(self) -> PredicateAtom<'tcx> { - let &PredicateKind::ForAll(binder) = self.kind(); + let binder = self.kind(); binder.skip_binder() } @@ -1083,21 +1088,21 @@ impl<'tcx> Predicate<'tcx> { /// Rebinding the returned atom can causes the previously bound variables /// to end up at the wrong binding level. pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> { - let &PredicateKind::ForAll(binder) = self.kind(); + let binder = self.kind(); binder.skip_binder() } /// Converts this to a `Binder>`. If the value was an /// `Atom`, then it is not allowed to contain escaping bound vars. pub fn bound_atom(self) -> Binder> { - let &PredicateKind::ForAll(binder) = self.kind(); + let binder = self.kind(); binder } /// Allows using a `Binder>` even if the given predicate previously /// contained unbound variables by shifting these variables outwards. pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder> { - let &PredicateKind::ForAll(binder) = self.kind(); + let binder = self.kind(); binder } } @@ -1117,13 +1122,6 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] -#[derive(HashStable, TypeFoldable)] -pub enum PredicateKind<'tcx> { - /// `for<'a>: ...` - ForAll(Binder>), -} - #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateAtom<'tcx> { @@ -1175,7 +1173,7 @@ pub enum PredicateAtom<'tcx> { impl<'tcx> Binder> { /// Wraps `self` with the given qualifier if this predicate has any unbound variables. pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::ForAll(self).to_predicate(tcx) + self.to_predicate(tcx) } } @@ -1387,7 +1385,7 @@ pub trait ToPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; } -impl ToPredicate<'tcx> for PredicateKind<'tcx> { +impl ToPredicate<'tcx> for Binder> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { tcx.mk_predicate(self) @@ -1398,7 +1396,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self); - tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self))) + tcx.mk_predicate(Binder::dummy(self)) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 33bb5454266..04bea024bd3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2068,7 +2068,7 @@ define_print_and_forward_display! { } ty::Predicate<'tcx> { - let ty::PredicateKind::ForAll(binder) = self.kind(); + let binder = self.kind(); p!(print(binder)) } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 0e933c82c3e..f2e41c88f15 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -228,14 +228,6 @@ 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::PredicateKind::ForAll(binder) => write!(f, "ForAll({:?})", binder), - } - } -} - impl fmt::Debug for ty::PredicateAtom<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -480,15 +472,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { } } -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::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll), - } - } -} - impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> { type Lifted = ty::PredicateAtom<'tcx>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index c783f964e14..aa7f746e52f 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -345,7 +345,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); - let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind(); + let binder = obligation.predicate.kind(); if binder.skip_binder().has_escaping_bound_vars() { match binder.skip_binder() { // Evaluation will discard candidates using the leak check. diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index adb20364ddf..0e8e15cb221 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>( // region relationships. implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); - let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + let binder = obligation.predicate.kind(); if binder.skip_binder().has_escaping_bound_vars() { vec![] } else { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index b28cc765330..64fefd82e06 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -5,7 +5,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_middle::hir::map as hir_map; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{ - self, Binder, Predicate, PredicateAtom, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness, + self, Binder, Predicate, PredicateAtom, ToPredicate, Ty, TyCtxt, WithConstness, }; use rustc_session::CrateDisambiguator; use rustc_span::symbol::Symbol; @@ -379,7 +379,7 @@ fn well_formed_types_in_env<'tcx>( match arg.unpack() { GenericArgKind::Type(ty) => { let binder = Binder::dummy(PredicateAtom::TypeWellFormedFromEnv(ty)); - Some(tcx.mk_predicate(PredicateKind::ForAll(binder))) + Some(tcx.mk_predicate(binder)) } // FIXME(eddyb) no WF conditions from lifetimes? diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index a7322711f90..c0920895b66 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -31,7 +31,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate let mut pred: Vec = predicates .iter() .map(|(out_pred, _)| { - let ty::PredicateKind::ForAll(binder) = out_pred.kind(); + let binder = out_pred.kind(); match binder.skip_binder() { ty::PredicateAtom::RegionOutlives(p) => p.to_string(), ty::PredicateAtom::TypeOutlives(p) => p.to_string(), 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 ad50a6a0405..d2a3bd3921d 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 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter(|p| !p.is_global()) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. - let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + let binder = obligation.predicate.kind(); match binder.skip_binder() { ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { if pred.def_id() == sized_trait {