diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 113e2220d4d..2b6b0759981 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>( tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { - let new = tcx.anonymize_late_bound_regions(pred.kind()); + let new = tcx.anonymize_late_bound_regions(pred.bound_atom()); tcx.reuse_or_mk_predicate(pred, new) } diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 987cb32d914..4d11804e2b4 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -46,7 +46,7 @@ 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::Binder>; fn variant(&self) -> &Self::Variant { - self.kind_ref() + self.bound_atom_ref() } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 78ff8671d13..e9b5b71f9c3 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -133,13 +133,13 @@ impl<'tcx> CtxtInterners<'tcx> { } #[inline(never)] - fn intern_predicate(&self, kind: Binder>) -> &'tcx PredicateInner<'tcx> { + fn intern_predicate(&self, binder: Binder>) -> &'tcx PredicateInner<'tcx> { self.predicate - .intern(kind, |kind| { - let flags = super::flags::FlagComputation::for_predicate(kind); + .intern(binder, |binder| { + let flags = super::flags::FlagComputation::for_predicate(binder); let predicate_struct = PredicateInner { - kind, + binder, flags: flags.flags, outer_exclusive_binder: flags.outer_exclusive_binder, }; @@ -1936,7 +1936,7 @@ impl<'tcx> Borrow> for Interned<'tcx, TyS<'tcx>> { // N.B., an `Interned` compares and hashes as a `PredicateKind`. impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> { fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool { - self.0.kind == other.0.kind + self.0.binder == other.0.binder } } @@ -1944,13 +1944,13 @@ impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {} impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> { fn hash(&self, s: &mut H) { - self.0.kind.hash(s) + self.0.binder.hash(s) } } impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { fn borrow<'a>(&'a self) -> &'a Binder> { - &self.0.kind + &self.0.binder } } @@ -2085,8 +2085,8 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_predicate(self, kind: Binder>) -> Predicate<'tcx> { - let inner = self.interners.intern_predicate(kind); + pub fn mk_predicate(self, binder: Binder>) -> Predicate<'tcx> { + let inner = self.interners.intern_predicate(binder); Predicate { inner } } @@ -2094,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn reuse_or_mk_predicate( self, pred: Predicate<'tcx>, - kind: Binder>, + binder: Binder>, ) -> Predicate<'tcx> { - if pred.kind() != kind { self.mk_predicate(kind) } else { pred } + if pred.bound_atom() != binder { self.mk_predicate(binder) } 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 b99587fe734..e25320634d0 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -22,9 +22,9 @@ impl FlagComputation { result } - pub fn for_predicate(kind: ty::Binder>) -> FlagComputation { + pub fn for_predicate(binder: ty::Binder>) -> FlagComputation { let mut result = FlagComputation::new(); - result.add_predicate_kind(kind); + result.add_predicate(binder); result } @@ -204,7 +204,7 @@ impl FlagComputation { } } - fn add_predicate_kind(&mut self, binder: ty::Binder>) { + fn add_predicate(&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 e023195605b..fc5a7b618bd 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: Binder>, + binder: Binder>, flags: TypeFlags, /// See the comment for the corresponding field of [TyS]. outer_exclusive_binder: ty::DebruijnIndex, @@ -1060,16 +1060,6 @@ impl Hash for Predicate<'_> { impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { - #[inline(always)] - pub fn kind(self) -> Binder> { - self.inner.kind - } - - #[inline(always)] - pub fn kind_ref(&self) -> &Binder> { - &self.inner.kind - } - /// Returns the inner `PredicateAtom`. /// /// The returned atom may contain unbound variables bound to binders skipped in this method. @@ -1077,8 +1067,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 binder = self.kind(); - binder.skip_binder() + self.inner.binder.skip_binder() } /// Returns the inner `PredicateAtom`. @@ -1088,29 +1077,30 @@ 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 binder = self.kind(); - binder.skip_binder() + self.inner.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 binder = self.kind(); - binder + self.inner.binder + } + + pub fn bound_atom_ref(self) -> &'tcx Binder> { + &self.inner.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 binder = self.kind(); - binder + self.inner.binder } } impl<'a, 'tcx> HashStable> for Predicate<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let PredicateInner { - ref kind, + ref binder, // The other fields just provide fast access to information that is // also contained in `kind`, so no need to hash them. @@ -1118,7 +1108,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { outer_exclusive_binder: _, } = self.inner; - kind.hash_stable(hcx, hasher); + binder.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 04bea024bd3..fbfc8a40faf 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 binder = self.kind(); + let binder = self.bound_atom(); p!(print(binder)) } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 4c2c6d01a5f..1abb4fd32bf 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -224,7 +224,7 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> { impl fmt::Debug for ty::Predicate<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.kind()) + write!(f, "{:?}", self.bound_atom()) } } @@ -1017,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { fn super_fold_with>(self, folder: &mut F) -> Self { - let new = self.inner.kind.fold_with(folder); + let new = self.inner.binder.fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.inner.kind.super_visit_with(visitor) + self.inner.binder.visit_with(visitor) } fn visit_with>(&self, visitor: &mut V) -> ControlFlow { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index aa7f746e52f..86c5209354c 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 binder = obligation.predicate.kind(); + let binder = obligation.predicate.bound_atom(); 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 0e8e15cb221..dc2eaf82d09 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 binder = obligation.predicate.kind(); + let binder = obligation.predicate.bound_atom(); if binder.skip_binder().has_escaping_bound_vars() { vec![] } else { diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index c0920895b66..437d19e35f5 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 binder = out_pred.kind(); + let binder = out_pred.bound_atom(); 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 d2a3bd3921d..9306b198051 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 binder = obligation.predicate.kind(); + let binder = obligation.predicate.bound_atom(); match binder.skip_binder() { ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { if pred.def_id() == sized_trait {