From 8278314a8bf76c9d56072d294ee1d5ba76551cb6 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 21 Dec 2020 22:49:03 -0500 Subject: [PATCH 01/15] Remove PredicateKind::Atom --- .../src/infer/canonical/query_response.rs | 3 +- compiler/rustc_infer/src/traits/util.rs | 1 - compiler/rustc_middle/src/ty/flags.rs | 1 - compiler/rustc_middle/src/ty/mod.rs | 45 +++-------- compiler/rustc_middle/src/ty/print/pretty.rs | 1 - .../rustc_middle/src/ty/structural_impls.rs | 2 - .../src/traits/fulfill.rs | 76 ++++++++++--------- .../src/implied_outlives_bounds.rs | 8 +- compiler/rustc_typeck/src/collect.rs | 7 +- compiler/rustc_typeck/src/outlives/mod.rs | 12 ++- .../repeated_projection_type.stderr | 2 +- .../src/needless_pass_by_value.rs | 14 ++-- 12 files changed, 72 insertions(+), 100 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 71ce50f745372..6dbaf8d225a7a 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -541,8 +541,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { span_bug!(cause.span, "unexpected const outlives {:?}", constraint); } }; - let predicate = - predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll); + let predicate = predicate.rebind(atom).potentially_quantified(self.tcx); Obligation::new(cause.clone(), param_env, predicate) }) diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 8273c2d291d09..d9ef5d88f1cfa 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -14,7 +14,6 @@ pub fn anonymize_predicate<'tcx>( let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder)); tcx.reuse_or_mk_predicate(pred, new) } - ty::PredicateKind::Atom(_) => pred, } } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 4de3d15924862..47ada10f55f84 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -211,7 +211,6 @@ impl FlagComputation { computation.add_predicate_atom(atom) }); } - ty::PredicateKind::Atom(atom) => self.add_predicate_atom(atom), } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 1399fc76e02d6..539506409660c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1037,7 +1037,7 @@ crate struct PredicateInner<'tcx> { } #[cfg(target_arch = "x86_64")] -static_assert_size!(PredicateInner<'_>, 48); +static_assert_size!(PredicateInner<'_>, 40); #[derive(Clone, Copy, Lift)] pub struct Predicate<'tcx> { @@ -1074,10 +1074,6 @@ impl<'tcx> Predicate<'tcx> { pub fn skip_binders(self) -> PredicateAtom<'tcx> { match self.kind() { &PredicateKind::ForAll(binder) => binder.skip_binder(), - &PredicateKind::Atom(atom) => { - debug_assert!(!atom.has_escaping_bound_vars()); - atom - } } } @@ -1090,7 +1086,6 @@ impl<'tcx> Predicate<'tcx> { pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> { match self.kind() { &PredicateKind::ForAll(binder) => binder.skip_binder(), - &PredicateKind::Atom(atom) => atom, } } @@ -1099,19 +1094,14 @@ impl<'tcx> Predicate<'tcx> { pub fn bound_atom(self) -> Binder> { match self.kind() { &PredicateKind::ForAll(binder) => binder, - &PredicateKind::Atom(atom) => { - debug_assert!(!atom.has_escaping_bound_vars()); - Binder::dummy(atom) - } } } /// 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> { + pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder> { match self.kind() { &PredicateKind::ForAll(binder) => binder, - &PredicateKind::Atom(atom) => Binder::wrap_nonbinding(tcx, atom), } } } @@ -1136,7 +1126,6 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { pub enum PredicateKind<'tcx> { /// `for<'a>: ...` ForAll(Binder>), - Atom(PredicateAtom<'tcx>), } #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] @@ -1189,16 +1178,8 @@ 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>, - qualifier: impl FnOnce(Binder>) -> PredicateKind<'tcx>, - ) -> Predicate<'tcx> { - match self.no_bound_vars() { - Some(atom) => PredicateKind::Atom(atom), - None => qualifier(self), - } - .to_predicate(tcx) + pub fn potentially_quantified(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::ForAll(self).to_predicate(tcx) } } @@ -1289,11 +1270,7 @@ impl<'tcx> Predicate<'tcx> { let substs = trait_ref.skip_binder().substs; let pred = self.skip_binders(); let new = pred.subst(tcx, substs); - if new != pred { - ty::Binder::bind(new).potentially_quantified(tcx, PredicateKind::ForAll) - } else { - self - } + if new != pred { ty::Binder::bind(new).potentially_quantified(tcx) } else { self } } } @@ -1425,7 +1402,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::Atom(self)) + tcx.mk_predicate(PredicateKind::ForAll(Binder::dummy(self))) } } @@ -1450,27 +1427,25 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { self.value .map_bound(|value| PredicateAtom::Trait(value, self.constness)) - .potentially_quantified(tcx, PredicateKind::ForAll) + .potentially_quantified(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::RegionOutlives) - .potentially_quantified(tcx, PredicateKind::ForAll) + self.map_bound(PredicateAtom::RegionOutlives).potentially_quantified(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::TypeOutlives) - .potentially_quantified(tcx, PredicateKind::ForAll) + self.map_bound(PredicateAtom::TypeOutlives).potentially_quantified(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx, PredicateKind::ForAll) + self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 893572785f76b..bc9ea3728b61a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2069,7 +2069,6 @@ define_print_and_forward_display! { ty::Predicate<'tcx> { match self.kind() { - &ty::PredicateKind::Atom(atom) => p!(print(atom)), ty::PredicateKind::ForAll(binder) => p!(print(binder)), } } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7a1ca6a6c2bfc..934d97d00e846 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -232,7 +232,6 @@ 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), - ty::PredicateKind::Atom(atom) => write!(f, "{:?}", atom), } } } @@ -486,7 +485,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { match self { ty::PredicateKind::ForAll(binder) => tcx.lift(binder).map(ty::PredicateKind::ForAll), - ty::PredicateKind::Atom(atom) => tcx.lift(atom).map(ty::PredicateKind::Atom), } } } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index a04f816b0f8a0..55d5331ae37b7 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -346,45 +346,47 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); match *obligation.predicate.kind() { - ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { - // Evaluation will discard candidates using the leak check. - // This means we need to pass it the bound version of our - // predicate. - ty::PredicateAtom::Trait(trait_ref, _constness) => { - let trait_obligation = obligation.with(binder.rebind(trait_ref)); - - self.process_trait_obligation( - obligation, - trait_obligation, - &mut pending_obligation.stalled_on, - ) - } - ty::PredicateAtom::Projection(data) => { - let project_obligation = obligation.with(binder.rebind(data)); + ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => { + match binder.skip_binder() { + // Evaluation will discard candidates using the leak check. + // This means we need to pass it the bound version of our + // predicate. + ty::PredicateAtom::Trait(trait_ref, _constness) => { + let trait_obligation = obligation.with(binder.rebind(trait_ref)); + + self.process_trait_obligation( + obligation, + trait_obligation, + &mut pending_obligation.stalled_on, + ) + } + ty::PredicateAtom::Projection(data) => { + let project_obligation = obligation.with(binder.rebind(data)); - self.process_projection_obligation( - project_obligation, - &mut pending_obligation.stalled_on, - ) - } - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::ObjectSafe(_) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => { - let pred = infcx.replace_bound_vars_with_placeholders(binder); - ProcessResult::Changed(mk_pending(vec![ - obligation.with(pred.to_predicate(self.selcx.tcx())), - ])) - } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { - bug!("TypeWellFormedFromEnv is only used for Chalk") + self.process_projection_obligation( + project_obligation, + &mut pending_obligation.stalled_on, + ) + } + ty::PredicateAtom::RegionOutlives(_) + | ty::PredicateAtom::TypeOutlives(_) + | ty::PredicateAtom::WellFormed(_) + | ty::PredicateAtom::ObjectSafe(_) + | ty::PredicateAtom::ClosureKind(..) + | ty::PredicateAtom::Subtype(_) + | ty::PredicateAtom::ConstEvaluatable(..) + | ty::PredicateAtom::ConstEquate(..) => { + let pred = infcx.replace_bound_vars_with_placeholders(binder); + ProcessResult::Changed(mk_pending(vec![ + obligation.with(pred.to_predicate(self.selcx.tcx())), + ])) + } + ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + bug!("TypeWellFormedFromEnv is only used for Chalk") + } } - }, - ty::PredicateKind::Atom(atom) => match atom { + } + ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { ty::PredicateAtom::Trait(data, _) => { let trait_obligation = obligation.with(Binder::dummy(data)); diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index 97017fbf2e56a..a4da22fc2ca83 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -95,8 +95,12 @@ fn compute_implied_outlives_bounds<'tcx>( implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); match obligation.predicate.kind() { - &ty::PredicateKind::ForAll(..) => vec![], - &ty::PredicateKind::Atom(atom) => match atom { + &ty::PredicateKind::ForAll(binder) + if binder.skip_binder().has_escaping_bound_vars() => + { + vec![] + } + &ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { ty::PredicateAtom::Trait(..) | ty::PredicateAtom::Subtype(..) | ty::PredicateAtom::Projection(..) diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index a6677328f8f88..b1242f0d1d518 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1949,10 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives( ty::OutlivesPredicate(ty, re_root_empty), )); - predicates.insert(( - predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll), - span, - )); + predicates.insert((predicate.potentially_quantified(tcx), span)); } } @@ -1996,7 +1993,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP ty::Binder::bind(ty::PredicateAtom::TypeOutlives( ty::OutlivesPredicate(ty, region), )) - .potentially_quantified(tcx, ty::PredicateKind::ForAll), + .potentially_quantified(tcx), lifetime.span, )); } diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index b1f79331d5f62..649edfb8f5231 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -31,13 +31,11 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate let mut pred: Vec = predicates .iter() .map(|(out_pred, _)| match out_pred.kind() { - ty::PredicateKind::Atom(ty::PredicateAtom::RegionOutlives(p)) => { - p.to_string() - } - ty::PredicateKind::Atom(ty::PredicateAtom::TypeOutlives(p)) => { - p.to_string() - } - err => bug!("unexpected predicate {:?}", err), + ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { + ty::PredicateAtom::RegionOutlives(p) => p.to_string(), + ty::PredicateAtom::TypeOutlives(p) => p.to_string(), + err => bug!("unexpected predicate {:?}", err), + }, }) .collect(); pred.sort(); diff --git a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr index fee8b06e94c0b..fab36adb0f44e 100644 --- a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr +++ b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr @@ -1,4 +1,4 @@ -error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))` +error: cannot specialize on `ForAll(Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))))` --> $DIR/repeated_projection_type.rs:19:1 | LL | / impl> X for V { 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 a435f86bfd8d5..ad50a6a0405fc 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,13 +115,15 @@ 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. - if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() { - if pred.def_id() == sized_trait { - return None; + let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + match binder.skip_binder() { + ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { + if pred.def_id() == sized_trait { + return None; + } + Some(pred) } - Some(pred) - } else { - None + _ => None, } }) .collect::>(); From 4cb3d6f983cfeab13171a7171425b624545b9ccc Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Wed, 23 Dec 2020 13:16:25 -0500 Subject: [PATCH 02/15] Intermediate formatting and such --- compiler/rustc_middle/src/ty/flags.rs | 9 +-- compiler/rustc_middle/src/ty/mod.rs | 20 ++--- compiler/rustc_middle/src/ty/print/pretty.rs | 5 +- .../rustc_middle/src/ty/structural_impls.rs | 4 +- .../src/traits/fulfill.rs | 80 +++++++++---------- .../src/implied_outlives_bounds.rs | 14 ++-- compiler/rustc_typeck/src/outlives/mod.rs | 7 +- 7 files changed, 64 insertions(+), 75 deletions(-) diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 47ada10f55f84..b7e045534b2ec 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -205,13 +205,8 @@ impl FlagComputation { } fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) { - match kind { - ty::PredicateKind::ForAll(binder) => { - self.bound_computation(binder, |computation, atom| { - computation.add_predicate_atom(atom) - }); - } - } + let ty::PredicateKind::ForAll(binder) = kind; + self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom)); } fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 539506409660c..97f8cc0a2398b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1072,9 +1072,8 @@ impl<'tcx> Predicate<'tcx> { /// /// Note that this method panics in case this predicate has unbound variables. pub fn skip_binders(self) -> PredicateAtom<'tcx> { - match self.kind() { - &PredicateKind::ForAll(binder) => binder.skip_binder(), - } + let &PredicateKind::ForAll(binder) = self.kind(); + binder.skip_binder() } /// Returns the inner `PredicateAtom`. @@ -1084,25 +1083,22 @@ 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> { - match self.kind() { - &PredicateKind::ForAll(binder) => binder.skip_binder(), - } + let &PredicateKind::ForAll(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> { - match self.kind() { - &PredicateKind::ForAll(binder) => binder, - } + let &PredicateKind::ForAll(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> { - match self.kind() { - &PredicateKind::ForAll(binder) => binder, - } + let &PredicateKind::ForAll(binder) = self.kind(); + binder } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index bc9ea3728b61a..33bb54542660a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2068,9 +2068,8 @@ define_print_and_forward_display! { } ty::Predicate<'tcx> { - match self.kind() { - ty::PredicateKind::ForAll(binder) => p!(print(binder)), - } + let ty::PredicateKind::ForAll(binder) = self.kind(); + p!(print(binder)) } ty::PredicateAtom<'tcx> { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 934d97d00e846..0e933c82c3e6b 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1034,12 +1034,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 = ty::PredicateKind::super_fold_with(self.inner.kind, folder); + let new = self.inner.kind.super_fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - ty::PredicateKind::super_visit_with(&self.inner.kind, visitor) + self.inner.kind.super_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 55d5331ae37b7..c783f964e14c6 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -345,48 +345,48 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); - match *obligation.predicate.kind() { - ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => { - match binder.skip_binder() { - // Evaluation will discard candidates using the leak check. - // This means we need to pass it the bound version of our - // predicate. - ty::PredicateAtom::Trait(trait_ref, _constness) => { - let trait_obligation = obligation.with(binder.rebind(trait_ref)); - - self.process_trait_obligation( - obligation, - trait_obligation, - &mut pending_obligation.stalled_on, - ) - } - ty::PredicateAtom::Projection(data) => { - let project_obligation = obligation.with(binder.rebind(data)); + let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind(); + if binder.skip_binder().has_escaping_bound_vars() { + match binder.skip_binder() { + // Evaluation will discard candidates using the leak check. + // This means we need to pass it the bound version of our + // predicate. + ty::PredicateAtom::Trait(trait_ref, _constness) => { + let trait_obligation = obligation.with(binder.rebind(trait_ref)); - self.process_projection_obligation( - project_obligation, - &mut pending_obligation.stalled_on, - ) - } - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::ObjectSafe(_) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => { - let pred = infcx.replace_bound_vars_with_placeholders(binder); - ProcessResult::Changed(mk_pending(vec![ - obligation.with(pred.to_predicate(self.selcx.tcx())), - ])) - } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { - bug!("TypeWellFormedFromEnv is only used for Chalk") - } + self.process_trait_obligation( + obligation, + trait_obligation, + &mut pending_obligation.stalled_on, + ) + } + ty::PredicateAtom::Projection(data) => { + let project_obligation = obligation.with(binder.rebind(data)); + + self.process_projection_obligation( + project_obligation, + &mut pending_obligation.stalled_on, + ) + } + ty::PredicateAtom::RegionOutlives(_) + | ty::PredicateAtom::TypeOutlives(_) + | ty::PredicateAtom::WellFormed(_) + | ty::PredicateAtom::ObjectSafe(_) + | ty::PredicateAtom::ClosureKind(..) + | ty::PredicateAtom::Subtype(_) + | ty::PredicateAtom::ConstEvaluatable(..) + | ty::PredicateAtom::ConstEquate(..) => { + let pred = infcx.replace_bound_vars_with_placeholders(binder); + ProcessResult::Changed(mk_pending(vec![ + obligation.with(pred.to_predicate(self.selcx.tcx())), + ])) + } + ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + bug!("TypeWellFormedFromEnv is only used for Chalk") } } - ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { + } else { + match binder.skip_binder() { ty::PredicateAtom::Trait(data, _) => { let trait_obligation = obligation.with(Binder::dummy(data)); @@ -598,7 +598,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ty::PredicateAtom::TypeWellFormedFromEnv(..) => { bug!("TypeWellFormedFromEnv is only used for Chalk") } - }, + } } } diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index a4da22fc2ca83..adb20364ddf6a 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -94,13 +94,11 @@ fn compute_implied_outlives_bounds<'tcx>( // region relationships. implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); - match obligation.predicate.kind() { - &ty::PredicateKind::ForAll(binder) - if binder.skip_binder().has_escaping_bound_vars() => - { - vec![] - } - &ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { + let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind(); + if binder.skip_binder().has_escaping_bound_vars() { + vec![] + } else { + match binder.skip_binder() { ty::PredicateAtom::Trait(..) | ty::PredicateAtom::Subtype(..) | ty::PredicateAtom::Projection(..) @@ -124,7 +122,7 @@ fn compute_implied_outlives_bounds<'tcx>( tcx.push_outlives_components(ty_a, &mut components); implied_bounds_from_components(r_b, components) } - }, + } } })); } diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index 649edfb8f5231..a7322711f90c5 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -30,12 +30,13 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec = predicates .iter() - .map(|(out_pred, _)| match out_pred.kind() { - ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { + .map(|(out_pred, _)| { + let ty::PredicateKind::ForAll(binder) = out_pred.kind(); + match binder.skip_binder() { ty::PredicateAtom::RegionOutlives(p) => p.to_string(), ty::PredicateAtom::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), - }, + } }) .collect(); pred.sort(); From 4cd6f85a07bf6a8db8288ff37cc11a2ecb72e1a7 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Wed, 23 Dec 2020 16:36:23 -0500 Subject: [PATCH 03/15] Remove PredicateKind --- compiler/rustc_infer/src/traits/util.rs | 8 ++--- compiler/rustc_middle/src/ty/codec.rs | 8 ++--- compiler/rustc_middle/src/ty/context.rs | 24 ++++++--------- compiler/rustc_middle/src/ty/flags.rs | 5 ++-- compiler/rustc_middle/src/ty/mod.rs | 30 +++++++++---------- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 17 ----------- .../src/traits/fulfill.rs | 2 +- .../src/implied_outlives_bounds.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 4 +-- compiler/rustc_typeck/src/outlives/mod.rs | 2 +- .../src/needless_pass_by_value.rs | 2 +- 12 files changed, 38 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index d9ef5d88f1cfa..113e2220d4d1f 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 9d371503e0a4c..987cb32d914df 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 a355242f5ce67..78ff8671d13af 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 b7e045534b2ec..b99587fe73499 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 97f8cc0a2398b..e023195605bbc 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 33bb54542660a..04bea024bd38e 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 0e933c82c3e6b..f2e41c88f15f4 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 c783f964e14c6..aa7f746e52fe3 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 adb20364ddf6a..0e8e15cb221cd 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 b28cc765330d2..64fefd82e06ab 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 a7322711f90c5..c0920895b66d6 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 ad50a6a0405fc..d2a3bd3921d27 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 { From 876192e8cda7d9a557326527328423587747ca88 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 01:14:07 -0500 Subject: [PATCH 04/15] fold_with not super_fold_with in TypeFoldable impl for Predicate --- compiler/rustc_middle/src/ty/structural_impls.rs | 2 +- .../min_specialization/repeated_projection_type.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index f2e41c88f15f4..4c2c6d01a5f5f 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1017,7 +1017,7 @@ 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.super_fold_with(folder); + let new = self.inner.kind.fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) } diff --git a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr index fab36adb0f44e..92208231b1735 100644 --- a/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr +++ b/src/test/ui/specialization/min_specialization/repeated_projection_type.stderr @@ -1,4 +1,4 @@ -error: cannot specialize on `ForAll(Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,))))` +error: cannot specialize on `Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id::This) }, (I,)))` --> $DIR/repeated_projection_type.rs:19:1 | LL | / impl> X for V { From e76476afe4179fb0c430cfcd86d061cc990a7bf7 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 01:58:33 -0500 Subject: [PATCH 05/15] Cleanup --- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 22 ++++++------- compiler/rustc_middle/src/ty/flags.rs | 6 ++-- compiler/rustc_middle/src/ty/mod.rs | 32 +++++++------------ compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 6 ++-- .../src/traits/fulfill.rs | 2 +- .../src/implied_outlives_bounds.rs | 2 +- compiler/rustc_typeck/src/outlives/mod.rs | 2 +- .../src/needless_pass_by_value.rs | 2 +- 11 files changed, 35 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 113e2220d4d1f..2b6b0759981ba 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 987cb32d914df..4d11804e2b4b2 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 78ff8671d13af..e9b5b71f9c3bd 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 b99587fe73499..e25320634d0ad 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 e023195605bbc..fc5a7b618bd12 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 04bea024bd38e..fbfc8a40faf02 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 4c2c6d01a5f5f..1abb4fd32bf51 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 aa7f746e52fe3..86c5209354c85 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 0e8e15cb221cd..dc2eaf82d092c 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 c0920895b66d6..437d19e35f5e9 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 d2a3bd3921d27..9306b198051c2 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 { From 7f24c21a5055f65e34decbf731b8a162502a0d0e Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 15:30:22 -0500 Subject: [PATCH 06/15] Use pred not binder --- src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9306b198051c2..6dc5654862b68 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 @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { // Note that we do not want to deal with qualified predicates here. let binder = obligation.predicate.bound_atom(); match binder.skip_binder() { - ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => { + ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { return None; } From 476bd5305872001efd7104d183dc9a90726f2b49 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 4 Jan 2021 16:50:36 -0500 Subject: [PATCH 07/15] Cleanup --- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 35 +++---------------- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 28 +++++---------- compiler/rustc_typeck/src/check/_match.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 4 +-- compiler/rustc_typeck/src/outlives/mod.rs | 11 +++--- src/librustdoc/clean/mod.rs | 4 +-- .../src/needless_pass_by_value.rs | 3 +- 9 files changed, 25 insertions(+), 66 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 6dbaf8d225a7a..ed2aca4dd8109 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -541,7 +541,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { span_bug!(cause.span, "unexpected const outlives {:?}", constraint); } }; - let predicate = predicate.rebind(atom).potentially_quantified(self.tcx); + let predicate = predicate.rebind(atom).to_predicate(self.tcx); Obligation::new(cause.clone(), param_env, predicate) }) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index fc5a7b618bd12..b3a9e4b668c82 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1070,16 +1070,6 @@ impl<'tcx> Predicate<'tcx> { self.inner.binder.skip_binder() } - /// Returns the inner `PredicateAtom`. - /// - /// Note that this method does not check if the predicate has unbound variables. - /// - /// 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> { - 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> { @@ -1089,12 +1079,6 @@ impl<'tcx> Predicate<'tcx> { 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> { - self.inner.binder - } } impl<'a, 'tcx> HashStable> for Predicate<'tcx> { @@ -1160,13 +1144,6 @@ pub enum PredicateAtom<'tcx> { TypeWellFormedFromEnv(Ty<'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> { - self.to_predicate(tcx) - } -} - /// The crate outlives map is computed during typeck and contains the /// outlives of every item in the local crate. You should not use it /// directly, because to do so will make your pass dependent on the @@ -1254,7 +1231,7 @@ impl<'tcx> Predicate<'tcx> { let substs = trait_ref.skip_binder().substs; let pred = self.skip_binders(); let new = pred.subst(tcx, substs); - if new != pred { ty::Binder::bind(new).potentially_quantified(tcx) } else { self } + if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self } } } @@ -1409,27 +1386,25 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.value - .map_bound(|value| PredicateAtom::Trait(value, self.constness)) - .potentially_quantified(tcx) + self.value.map_bound(|value| PredicateAtom::Trait(value, self.constness)).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::RegionOutlives).potentially_quantified(tcx) + self.map_bound(PredicateAtom::RegionOutlives).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::TypeOutlives).potentially_quantified(tcx) + self.map_bound(PredicateAtom::TypeOutlives).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::Projection).potentially_quantified(tcx) + self.map_bound(PredicateAtom::Projection).to_predicate(tcx) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index fbfc8a40faf02..5d291a6169f4c 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -627,7 +627,7 @@ pub trait PrettyPrinter<'tcx>: // may contain unbound variables. We therefore do this manually. // // FIXME(lcnr): Find out why exactly this is the case :) - let bound_predicate = predicate.bound_atom_with_opt_escaping(self.tcx()); + let bound_predicate = predicate.bound_atom(); if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() { let trait_ref = bound_predicate.rebind(pred.trait_ref); // Don't print +Sized, but rather +?Sized if absent. diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 8aa68e533a2e1..3a82ead08ab99 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -81,11 +81,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment, ) -> chalk_ir::InEnvironment>> { let clauses = self.environment.into_iter().map(|predicate| { - let (predicate, binders, _named_regions) = collect_bound_vars( - interner, - interner.tcx, - predicate.bound_atom_with_opt_escaping(interner.tcx), - ); + let (predicate, binders, _named_regions) = + collect_bound_vars(interner, interner.tcx, predicate.bound_atom()); let consequence = match predicate { ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))) @@ -136,11 +133,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predicate<'tcx> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData> { - let (predicate, binders, _named_regions) = collect_bound_vars( - interner, - interner.tcx, - self.bound_atom_with_opt_escaping(interner.tcx), - ); + let (predicate, binders, _named_regions) = + collect_bound_vars(interner, interner.tcx, self.bound_atom()); let value = match predicate { ty::PredicateAtom::Trait(predicate, _) => { @@ -573,11 +567,8 @@ impl<'tcx> LowerInto<'tcx, Option, ) -> Option>> { - let (predicate, binders, _named_regions) = collect_bound_vars( - interner, - interner.tcx, - self.bound_atom_with_opt_escaping(interner.tcx), - ); + let (predicate, binders, _named_regions) = + collect_bound_vars(interner, interner.tcx, self.bound_atom()); let value = match predicate { ty::PredicateAtom::Trait(predicate, _) => { Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner))) @@ -707,11 +698,8 @@ impl<'tcx> LowerInto<'tcx, Option, ) -> Option>> { - let (predicate, binders, _named_regions) = collect_bound_vars( - interner, - interner.tcx, - self.bound_atom_with_opt_escaping(interner.tcx), - ); + let (predicate, binders, _named_regions) = + collect_bound_vars(interner, interner.tcx, self.bound_atom()); match predicate { ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new( binders, diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 322ec9640f464..82fbbd3a77ea2 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -544,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.infcx.instantiate_opaque_types(id, self.body_id, self.param_env, ty, span); let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty(); for o in impl_trait_ret_ty.obligations { - match o.predicate.skip_binders_unchecked() { + match o.predicate.bound_atom().skip_binder() { ty::PredicateAtom::Trait(t, constness) => { let pred = ty::PredicateAtom::Trait( ty::TraitPredicate { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index b1242f0d1d518..20b4aa1bc049f 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1949,7 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives( ty::OutlivesPredicate(ty, re_root_empty), )); - predicates.insert((predicate.potentially_quantified(tcx), span)); + predicates.insert((predicate.to_predicate(tcx), span)); } } @@ -1993,7 +1993,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP ty::Binder::bind(ty::PredicateAtom::TypeOutlives( ty::OutlivesPredicate(ty, region), )) - .potentially_quantified(tcx), + .to_predicate(tcx), lifetime.span, )); } diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index 437d19e35f5e9..8c92fc1744adc 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -30,13 +30,10 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec = predicates .iter() - .map(|(out_pred, _)| { - let binder = out_pred.bound_atom(); - match binder.skip_binder() { - ty::PredicateAtom::RegionOutlives(p) => p.to_string(), - ty::PredicateAtom::TypeOutlives(p) => p.to_string(), - err => bug!("unexpected predicate {:?}", err), - } + .map(|(out_pred, _)| match out_pred.bound_atom().skip_binder() { + ty::PredicateAtom::RegionOutlives(p) => p.to_string(), + ty::PredicateAtom::TypeOutlives(p) => p.to_string(), + err => bug!("unexpected predicate {:?}", err), }) .collect(); pred.sort(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cafb65bc7f9cb..35d93c58a9db4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1686,7 +1686,7 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|bound| { // Note: The substs of opaque types can contain unbound variables, // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. - let bound_predicate = bound.bound_atom_with_opt_escaping(cx.tcx); + let bound_predicate = bound.bound_atom(); let trait_ref = match bound_predicate.skip_binder() { ty::PredicateAtom::Trait(tr, _constness) => { bound_predicate.rebind(tr.trait_ref) @@ -1711,7 +1711,7 @@ impl<'tcx> Clean for Ty<'tcx> { .iter() .filter_map(|bound| { if let ty::PredicateAtom::Projection(proj) = - bound.bound_atom_with_opt_escaping(cx.tcx).skip_binder() + bound.bound_atom().skip_binder() { if proj.projection_ty.trait_ref(cx.tcx) == trait_ref.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 6dc5654862b68..3e87ef03832d2 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,8 +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.bound_atom(); - match binder.skip_binder() { + match obligation.predicate.bound_atom().skip_binder() { ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { if pred.def_id() == sized_trait { return None; From 66c179946be7711a82d1060de3bf2085e38c1432 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Wed, 6 Jan 2021 16:12:02 -0500 Subject: [PATCH 08/15] Use no_bound_vars --- compiler/rustc_traits/src/implied_outlives_bounds.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index dc2eaf82d092c..cf7101ff7127a 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -94,11 +94,9 @@ 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.bound_atom(); - if binder.skip_binder().has_escaping_bound_vars() { - vec![] - } else { - match binder.skip_binder() { + match obligation.predicate.bound_atom().no_bound_vars() { + None => vec![], + Some(pred) => match pred { ty::PredicateAtom::Trait(..) | ty::PredicateAtom::Subtype(..) | ty::PredicateAtom::Projection(..) @@ -122,7 +120,7 @@ fn compute_implied_outlives_bounds<'tcx>( tcx.push_outlives_components(ty_a, &mut components); implied_bounds_from_components(r_b, components) } - } + }, } })); } From 3dea68de1d75c388beea3378a4d15371b713f157 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Thu, 7 Jan 2021 11:20:28 -0500 Subject: [PATCH 09/15] Review changes --- .../src/infer/canonical/query_response.rs | 6 +- compiler/rustc_infer/src/infer/combine.rs | 6 +- .../src/infer/error_reporting/mod.rs | 4 +- .../rustc_infer/src/infer/outlives/mod.rs | 25 ++--- compiler/rustc_infer/src/infer/sub.rs | 2 +- compiler/rustc_infer/src/traits/util.rs | 30 +++--- compiler/rustc_lint/src/builtin.rs | 12 +-- compiler/rustc_lint/src/traits.rs | 4 +- compiler/rustc_lint/src/unused.rs | 4 +- compiler/rustc_middle/src/ty/codec.rs | 8 +- compiler/rustc_middle/src/ty/context.rs | 14 +-- compiler/rustc_middle/src/ty/flags.rs | 28 ++--- compiler/rustc_middle/src/ty/mod.rs | 84 +++++++-------- compiler/rustc_middle/src/ty/print/pretty.rs | 30 +++--- .../rustc_middle/src/ty/structural_impls.rs | 70 ++++++------ .../borrow_check/diagnostics/region_errors.rs | 4 +- .../src/borrow_check/type_check/mod.rs | 8 +- .../src/transform/check_consts/validation.rs | 24 ++--- .../src/transform/function_item_references.rs | 8 +- compiler/rustc_privacy/src/lib.rs | 12 +-- .../rustc_trait_selection/src/opaque_types.rs | 26 ++--- .../src/traits/auto_trait.rs | 18 ++-- .../src/traits/const_evaluatable.rs | 4 +- .../src/traits/error_reporting/mod.rs | 51 ++++----- .../src/traits/error_reporting/suggestions.rs | 4 +- .../src/traits/fulfill.rs | 57 +++++----- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/object_safety.rs | 50 ++++----- .../src/traits/project.rs | 8 +- .../traits/query/type_op/prove_predicate.rs | 2 +- .../src/traits/select/confirmation.rs | 4 +- .../src/traits/select/mod.rs | 30 +++--- .../rustc_trait_selection/src/traits/wf.rs | 44 ++++---- compiler/rustc_traits/src/chalk/lowering.rs | 100 +++++++++--------- .../src/implied_outlives_bounds.rs | 24 ++--- .../src/normalize_erasing_regions.rs | 22 ++-- compiler/rustc_traits/src/type_op.rs | 4 +- compiler/rustc_ty_utils/src/ty.rs | 4 +- compiler/rustc_typeck/src/astconv/mod.rs | 6 +- compiler/rustc_typeck/src/check/_match.rs | 6 +- compiler/rustc_typeck/src/check/closure.rs | 10 +- compiler/rustc_typeck/src/check/coercion.rs | 4 +- compiler/rustc_typeck/src/check/dropck.rs | 8 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 26 ++--- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 8 +- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 4 +- .../rustc_typeck/src/check/method/confirm.rs | 4 +- compiler/rustc_typeck/src/check/method/mod.rs | 2 +- .../rustc_typeck/src/check/method/probe.rs | 24 ++--- .../rustc_typeck/src/check/method/suggest.rs | 16 +-- compiler/rustc_typeck/src/check/mod.rs | 6 +- compiler/rustc_typeck/src/check/wfcheck.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 29 ++--- .../rustc_typeck/src/collect/item_bounds.rs | 13 +-- .../src/constrained_generic_params.rs | 3 +- .../src/impl_wf_check/min_specialization.rs | 32 +++--- .../rustc_typeck/src/outlives/explicit.rs | 24 ++--- compiler/rustc_typeck/src/outlives/mod.rs | 10 +- src/librustdoc/clean/auto_trait.rs | 10 +- src/librustdoc/clean/mod.rs | 44 ++++---- src/librustdoc/clean/simplify.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 4 +- .../clippy/clippy_lints/src/methods/mod.rs | 2 +- .../src/needless_pass_by_value.rs | 9 +- .../src/unit_return_expecting_ord.rs | 6 +- .../clippy/clippy_lints/src/utils/mod.rs | 2 +- .../src/utils/qualify_min_const_fn.rs | 24 ++--- 67 files changed, 584 insertions(+), 593 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index ed2aca4dd8109..4357eb34add23 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -530,10 +530,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { let atom = match k1.unpack() { GenericArgKind::Lifetime(r1) => { - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2)) + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)) } GenericArgKind::Type(t1) => { - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t1, r2)) + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t1, r2)) } GenericArgKind::Const(..) => { // Consts cannot outlive one another, so we don't expect to @@ -663,7 +663,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { self.obligations.push(Obligation { cause: self.cause.clone(), param_env: self.param_env, - predicate: ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(sup, sub)) + predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub)) .to_predicate(self.infcx.tcx), recursion_depth: 0, }); diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index e38eebe23b1e1..b344086e95e77 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -358,7 +358,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { self.obligations.push(Obligation::new( self.trace.cause.clone(), self.param_env, - ty::PredicateAtom::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx), + ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx), )); } @@ -451,9 +451,9 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { b: &'tcx ty::Const<'tcx>, ) { let predicate = if a_is_expected { - ty::PredicateAtom::ConstEquate(a, b) + ty::PredicateKind::ConstEquate(a, b) } else { - ty::PredicateAtom::ConstEquate(b, a) + ty::PredicateKind::ConstEquate(b, a) }; self.obligations.push(Obligation::new( self.trace.cause.clone(), diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fee6f87ae42c3..c39daea0811e0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1706,8 +1706,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { for (predicate, _) in bounds { let predicate = predicate.subst(self.tcx, substs); - if let ty::PredicateAtom::Projection(projection_predicate) = - predicate.skip_binders() + if let ty::PredicateKind::Projection(projection_predicate) = + predicate.kind().skip_binder() { if projection_predicate.projection_ty.item_def_id == item_def_id { // We don't account for multiple `Future::Output = Ty` contraints. diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index de98cccf25689..13fc5b360a960 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -15,20 +15,21 @@ pub fn explicit_outlives_bounds<'tcx>( param_env .caller_bounds() .into_iter() - .map(ty::Predicate::skip_binders) + .map(ty::Predicate::kind) + .map(ty::Binder::skip_binder) .filter(|atom| !atom.has_escaping_bound_vars()) .filter_map(move |atom| match atom { - ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::Trait(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::TypeOutlives(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => None, - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => { + ty::PredicateKind::Projection(..) + | ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => { Some(OutlivesBound::RegionSubRegion(r_b, r_a)) } }) diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index a676c5e65a73b..668719851583c 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -100,7 +100,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { self.fields.obligations.push(Obligation::new( self.fields.trace.cause.clone(), self.fields.param_env, - ty::PredicateAtom::Subtype(ty::SubtypePredicate { + ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: self.a_is_expected, a, b, diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 2b6b0759981ba..13cf1e1083f7f 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.bound_atom()); + let new = tcx.anonymize_late_bound_regions(pred.kind()); tcx.reuse_or_mk_predicate(pred, new) } @@ -121,9 +121,9 @@ impl Elaborator<'tcx> { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(data, _) => { + ty::PredicateKind::Trait(data, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -145,36 +145,36 @@ impl Elaborator<'tcx> { self.stack.extend(obligations); } - ty::PredicateAtom::WellFormed(..) => { + ty::PredicateKind::WellFormed(..) => { // Currently, we do not elaborate WF predicates, // although we easily could. } - ty::PredicateAtom::ObjectSafe(..) => { + ty::PredicateKind::ObjectSafe(..) => { // Currently, we do not elaborate object-safe // predicates. } - ty::PredicateAtom::Subtype(..) => { + ty::PredicateKind::Subtype(..) => { // Currently, we do not "elaborate" predicates like `X <: Y`, // though conceivably we might. } - ty::PredicateAtom::Projection(..) => { + ty::PredicateKind::Projection(..) => { // Nothing to elaborate in a projection predicate. } - ty::PredicateAtom::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { // Nothing to elaborate when waiting for a closure's kind to be inferred. } - ty::PredicateAtom::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Currently, we do not elaborate const-evaluatable // predicates. } - ty::PredicateAtom::ConstEquate(..) => { + ty::PredicateKind::ConstEquate(..) => { // Currently, we do not elaborate const-equate // predicates. } - ty::PredicateAtom::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { // Nothing to elaborate from `'a: 'b`. } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_max, r_min)) => { // We know that `T: 'a` for some type `T`. We can // often elaborate this. For example, if we know that // `[U]: 'a`, that implies that `U: 'a`. Similarly, if @@ -204,7 +204,7 @@ impl Elaborator<'tcx> { if r.is_late_bound() { None } else { - Some(ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate( + Some(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate( r, r_min, ))) } @@ -212,7 +212,7 @@ impl Elaborator<'tcx> { Component::Param(p) => { let ty = tcx.mk_ty_param(p.index, p.name); - Some(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate( + Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( ty, r_min, ))) } @@ -237,7 +237,7 @@ impl Elaborator<'tcx> { }), ); } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeWellFormedFromEnv(..) => { // Nothing to elaborate } } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4e393df81fd8e..8cdb33ea3175f 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1550,13 +1550,13 @@ declare_lint_pass!( impl<'tcx> LateLintPass<'tcx> for TrivialConstraints { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { use rustc_middle::ty::fold::TypeFoldable; - use rustc_middle::ty::PredicateAtom::*; + use rustc_middle::ty::PredicateKind::*; if cx.tcx.features().trivial_bounds { let def_id = cx.tcx.hir().local_def_id(item.hir_id); let predicates = cx.tcx.predicates_of(def_id); for &(predicate, span) in predicates.predicates { - let predicate_kind_name = match predicate.skip_binders() { + let predicate_kind_name = match predicate.kind().skip_binder() { Trait(..) => "Trait", TypeOutlives(..) | RegionOutlives(..) => "Lifetime", @@ -1936,8 +1936,8 @@ impl ExplicitOutlivesRequirements { ) -> Vec> { inferred_outlives .iter() - .filter_map(|(pred, _)| match pred.skip_binders() { - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a { + .filter_map(|(pred, _)| match pred.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a { ty::ReEarlyBound(ebr) if ebr.index == index => Some(b), _ => None, }, @@ -1952,8 +1952,8 @@ impl ExplicitOutlivesRequirements { ) -> Vec> { inferred_outlives .iter() - .filter_map(|(pred, _)| match pred.skip_binders() { - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(a, b)) => { + .filter_map(|(pred, _)| match pred.kind().skip_binder() { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => { a.is_param(index).then_some(b) } _ => None, diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index d4f79036e5a18..b031c1108c66f 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -45,12 +45,12 @@ declare_lint_pass!( impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { - use rustc_middle::ty::PredicateAtom::*; + use rustc_middle::ty::PredicateKind::*; let def_id = cx.tcx.hir().local_def_id(item.hir_id); let predicates = cx.tcx.explicit_predicates_of(def_id); for &(predicate, span) in predicates.predicates { - let trait_predicate = match predicate.skip_binders() { + let trait_predicate = match predicate.kind().skip_binder() { Trait(trait_predicate, _constness) => trait_predicate, _ => continue, }; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index bc7363a69a6e8..c1a3eecbbc7ef 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -202,8 +202,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { let mut has_emitted = false; for &(predicate, _) in cx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. - if let ty::PredicateAtom::Trait(ref poly_trait_predicate, _) = - predicate.skip_binders() + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = + predicate.kind().skip_binder() { let def_id = poly_trait_predicate.trait_ref.def_id; let descr_pre = diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 4d11804e2b4b2..6fa9c414bc043 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::Binder>; + type Variant = ty::Binder>; fn variant(&self) -> &Self::Variant { - self.bound_atom_ref() + 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::Binder::>::decode) + decoder.with_position(shorthand, ty::Binder::>::decode) } else { - ty::Binder::>::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 e9b5b71f9c3bd..ee4e7c8f0cc6f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -19,7 +19,7 @@ use crate::ty::TyKind::*; use crate::ty::{ 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, + IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind, 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, binder: Binder>) -> &'tcx PredicateInner<'tcx> { + fn intern_predicate(&self, binder: Binder>) -> &'tcx PredicateInner<'tcx> { self.predicate .intern(binder, |binder| { let flags = super::flags::FlagComputation::for_predicate(binder); @@ -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 Binder> { +impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { + fn borrow<'a>(&'a self) -> &'a Binder> { &self.0.binder } } @@ -2085,7 +2085,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_predicate(self, binder: Binder>) -> Predicate<'tcx> { + 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>, - binder: Binder>, + binder: Binder>, ) -> Predicate<'tcx> { - if pred.bound_atom() != binder { self.mk_predicate(binder) } else { pred } + if pred.kind() != 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 e25320634d0ad..6ecd1ebf37039 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(binder: ty::Binder>) -> FlagComputation { + pub fn for_predicate(binder: ty::Binder>) -> FlagComputation { let mut result = FlagComputation::new(); result.add_predicate(binder); result @@ -204,46 +204,46 @@ impl FlagComputation { } } - fn add_predicate(&mut self, binder: ty::Binder>) { + fn add_predicate(&mut self, binder: ty::Binder>) { self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom)); } - fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) { + fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) { match atom { - ty::PredicateAtom::Trait(trait_pred, _constness) => { + ty::PredicateKind::Trait(trait_pred, _constness) => { self.add_substs(trait_pred.trait_ref.substs); } - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(a, b)) => { + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => { self.add_region(a); self.add_region(b); } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, region)) => { self.add_ty(ty); self.add_region(region); } - ty::PredicateAtom::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => { + ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => { self.add_ty(a); self.add_ty(b); } - ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { + ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { self.add_projection_ty(projection_ty); self.add_ty(ty); } - ty::PredicateAtom::WellFormed(arg) => { + ty::PredicateKind::WellFormed(arg) => { self.add_substs(slice::from_ref(&arg)); } - ty::PredicateAtom::ObjectSafe(_def_id) => {} - ty::PredicateAtom::ClosureKind(_def_id, substs, _kind) => { + ty::PredicateKind::ObjectSafe(_def_id) => {} + ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => { self.add_substs(substs); } - ty::PredicateAtom::ConstEvaluatable(_def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(_def_id, substs) => { self.add_substs(substs); } - ty::PredicateAtom::ConstEquate(expected, found) => { + ty::PredicateKind::ConstEquate(expected, found) => { self.add_const(expected); self.add_const(found); } - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { + ty::PredicateKind::TypeWellFormedFromEnv(ty) => { self.add_ty(ty); } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index b3a9e4b668c82..f8ae4a118db74 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> { - binder: Binder>, + binder: Binder>, flags: TypeFlags, /// See the comment for the corresponding field of [TyS]. outer_exclusive_binder: ty::DebruijnIndex, @@ -1060,23 +1060,13 @@ impl Hash for Predicate<'_> { impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { - /// Returns the inner `PredicateAtom`. - /// - /// The returned atom may contain unbound variables bound to binders skipped in this method. - /// It is safe to reapply binders to the given atom. - /// - /// Note that this method panics in case this predicate has unbound variables. - pub fn skip_binders(self) -> PredicateAtom<'tcx> { - self.inner.binder.skip_binder() - } - - /// Converts this to a `Binder>`. If the value was an + /// 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> { + pub fn kind(self) -> Binder> { self.inner.binder } - pub fn bound_atom_ref(self) -> &'tcx Binder> { + pub fn kind_ref(self) -> &'tcx Binder> { &self.inner.binder } } @@ -1098,7 +1088,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] -pub enum PredicateAtom<'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. @@ -1229,7 +1219,7 @@ impl<'tcx> Predicate<'tcx> { // from the substitution and the value being substituted into, and // this trick achieves that). let substs = trait_ref.skip_binder().substs; - let pred = self.skip_binders(); + let pred = self.kind().skip_binder(); let new = pred.subst(tcx, substs); if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self } } @@ -1352,14 +1342,14 @@ pub trait ToPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; } -impl ToPredicate<'tcx> for Binder> { +impl ToPredicate<'tcx> for Binder> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { tcx.mk_predicate(self) } } -impl ToPredicate<'tcx> for PredicateAtom<'tcx> { +impl ToPredicate<'tcx> for PredicateKind<'tcx> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { debug_assert!(!self.has_escaping_bound_vars(), "escaping bound vars for {:?}", self); @@ -1369,7 +1359,7 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateAtom::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness) + PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness) .to_predicate(tcx) } } @@ -1386,62 +1376,62 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.value.map_bound(|value| PredicateAtom::Trait(value, self.constness)).to_predicate(tcx) + self.value.map_bound(|value| PredicateKind::Trait(value, self.constness)).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::RegionOutlives).to_predicate(tcx) + self.map_bound(PredicateKind::RegionOutlives).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::TypeOutlives).to_predicate(tcx) + self.map_bound(PredicateKind::TypeOutlives).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.map_bound(PredicateAtom::Projection).to_predicate(tcx) + self.map_bound(PredicateKind::Projection).to_predicate(tcx) } } impl<'tcx> Predicate<'tcx> { pub fn to_opt_poly_trait_ref(self) -> Option>> { - let predicate = self.bound_atom(); + let predicate = self.kind(); match predicate.skip_binder() { - PredicateAtom::Trait(t, constness) => { + PredicateKind::Trait(t, constness) => { Some(ConstnessAnd { constness, value: predicate.rebind(t.trait_ref) }) } - PredicateAtom::Projection(..) - | PredicateAtom::Subtype(..) - | PredicateAtom::RegionOutlives(..) - | PredicateAtom::WellFormed(..) - | PredicateAtom::ObjectSafe(..) - | PredicateAtom::ClosureKind(..) - | PredicateAtom::TypeOutlives(..) - | PredicateAtom::ConstEvaluatable(..) - | PredicateAtom::ConstEquate(..) - | PredicateAtom::TypeWellFormedFromEnv(..) => None, + PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::TypeOutlives(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) + | PredicateKind::TypeWellFormedFromEnv(..) => None, } } pub fn to_opt_type_outlives(self) -> Option> { - let predicate = self.bound_atom(); + let predicate = self.kind(); match predicate.skip_binder() { - PredicateAtom::TypeOutlives(data) => Some(predicate.rebind(data)), - PredicateAtom::Trait(..) - | PredicateAtom::Projection(..) - | PredicateAtom::Subtype(..) - | PredicateAtom::RegionOutlives(..) - | PredicateAtom::WellFormed(..) - | PredicateAtom::ObjectSafe(..) - | PredicateAtom::ClosureKind(..) - | PredicateAtom::ConstEvaluatable(..) - | PredicateAtom::ConstEquate(..) - | PredicateAtom::TypeWellFormedFromEnv(..) => None, + PredicateKind::TypeOutlives(data) => Some(predicate.rebind(data)), + PredicateKind::Trait(..) + | PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) + | PredicateKind::TypeWellFormedFromEnv(..) => None, } } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 5d291a6169f4c..ed24f2c9bfb2d 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -627,8 +627,8 @@ pub trait PrettyPrinter<'tcx>: // may contain unbound variables. We therefore do this manually. // // FIXME(lcnr): Find out why exactly this is the case :) - let bound_predicate = predicate.bound_atom(); - if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() { + let bound_predicate = predicate.kind(); + if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { let trait_ref = bound_predicate.rebind(pred.trait_ref); // Don't print +Sized, but rather +?Sized if absent. if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() { @@ -2068,38 +2068,38 @@ define_print_and_forward_display! { } ty::Predicate<'tcx> { - let binder = self.bound_atom(); + let binder = self.kind(); p!(print(binder)) } - ty::PredicateAtom<'tcx> { + ty::PredicateKind<'tcx> { match *self { - ty::PredicateAtom::Trait(ref data, constness) => { + ty::PredicateKind::Trait(ref data, constness) => { if let hir::Constness::Const = constness { p!("const "); } p!(print(data)) } - ty::PredicateAtom::Subtype(predicate) => p!(print(predicate)), - ty::PredicateAtom::RegionOutlives(predicate) => p!(print(predicate)), - ty::PredicateAtom::TypeOutlives(predicate) => p!(print(predicate)), - ty::PredicateAtom::Projection(predicate) => p!(print(predicate)), - ty::PredicateAtom::WellFormed(arg) => p!(print(arg), " well-formed"), - ty::PredicateAtom::ObjectSafe(trait_def_id) => { + ty::PredicateKind::Subtype(predicate) => p!(print(predicate)), + ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)), + ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)), + ty::PredicateKind::Projection(predicate) => p!(print(predicate)), + ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"), + ty::PredicateKind::ObjectSafe(trait_def_id) => { p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe") } - ty::PredicateAtom::ClosureKind(closure_def_id, _closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => { p!("the closure `", print_value_path(closure_def_id, &[]), write("` implements the trait `{}`", kind)) } - ty::PredicateAtom::ConstEvaluatable(def, substs) => { + ty::PredicateKind::ConstEvaluatable(def, substs) => { p!("the constant `", print_value_path(def.did, substs), "` can be evaluated") } - ty::PredicateAtom::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { p!("the constant `", print(c1), "` equals `", print(c2), "`") } - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { + ty::PredicateKind::TypeWellFormedFromEnv(ty) => { p!("the type `", print(ty), "` is found in the environment") } } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 1abb4fd32bf51..ca625fddc99ab 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -224,35 +224,35 @@ 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.bound_atom()) + write!(f, "{:?}", self.kind()) } } -impl fmt::Debug for ty::PredicateAtom<'tcx> { +impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ty::PredicateAtom::Trait(ref a, constness) => { + ty::PredicateKind::Trait(ref a, constness) => { if let hir::Constness::Const = constness { write!(f, "const ")?; } a.fmt(f) } - ty::PredicateAtom::Subtype(ref pair) => pair.fmt(f), - ty::PredicateAtom::RegionOutlives(ref pair) => pair.fmt(f), - ty::PredicateAtom::TypeOutlives(ref pair) => pair.fmt(f), - ty::PredicateAtom::Projection(ref pair) => pair.fmt(f), - ty::PredicateAtom::WellFormed(data) => write!(f, "WellFormed({:?})", data), - ty::PredicateAtom::ObjectSafe(trait_def_id) => { + ty::PredicateKind::Subtype(ref pair) => pair.fmt(f), + ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f), + ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f), + ty::PredicateKind::Projection(ref pair) => pair.fmt(f), + ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data), + ty::PredicateKind::ObjectSafe(trait_def_id) => { write!(f, "ObjectSafe({:?})", trait_def_id) } - ty::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind) } - ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) } - ty::PredicateAtom::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { + ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), + ty::PredicateKind::TypeWellFormedFromEnv(ty) => { write!(f, "TypeWellFormedFromEnv({:?})", ty) } } @@ -472,40 +472,40 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { } } -impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> { - type Lifted = ty::PredicateAtom<'tcx>; +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::PredicateAtom::Trait(data, constness) => { - tcx.lift(data).map(|data| ty::PredicateAtom::Trait(data, constness)) + ty::PredicateKind::Trait(data, constness) => { + tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness)) } - ty::PredicateAtom::Subtype(data) => tcx.lift(data).map(ty::PredicateAtom::Subtype), - ty::PredicateAtom::RegionOutlives(data) => { - tcx.lift(data).map(ty::PredicateAtom::RegionOutlives) + ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype), + ty::PredicateKind::RegionOutlives(data) => { + tcx.lift(data).map(ty::PredicateKind::RegionOutlives) } - ty::PredicateAtom::TypeOutlives(data) => { - tcx.lift(data).map(ty::PredicateAtom::TypeOutlives) + ty::PredicateKind::TypeOutlives(data) => { + tcx.lift(data).map(ty::PredicateKind::TypeOutlives) } - ty::PredicateAtom::Projection(data) => { - tcx.lift(data).map(ty::PredicateAtom::Projection) + ty::PredicateKind::Projection(data) => { + tcx.lift(data).map(ty::PredicateKind::Projection) } - ty::PredicateAtom::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateAtom::WellFormed), - ty::PredicateAtom::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::PredicateAtom::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) }) } - ty::PredicateAtom::ObjectSafe(trait_def_id) => { - Some(ty::PredicateAtom::ObjectSafe(trait_def_id)) + ty::PredicateKind::ObjectSafe(trait_def_id) => { + Some(ty::PredicateKind::ObjectSafe(trait_def_id)) } - ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { - tcx.lift(substs).map(|substs| ty::PredicateAtom::ConstEvaluatable(def_id, substs)) + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + tcx.lift(substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs)) } - ty::PredicateAtom::ConstEquate(c1, c2) => { - tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2)) + ty::PredicateKind::ConstEquate(c1, c2) => { + tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2)) } - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { - tcx.lift(ty).map(ty::PredicateAtom::TypeWellFormedFromEnv) + ty::PredicateKind::TypeWellFormedFromEnv(ty) => { + tcx.lift(ty).map(ty::PredicateKind::TypeWellFormedFromEnv) } } } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs index 78da43c31c0fb..ab83fc8dfaf75 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs @@ -590,8 +590,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let mut found = false; for (bound, _) in bounds { - if let ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_, r)) = - bound.skip_binders() + if let ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_, r)) = + bound.kind().skip_binder() { let r = r.subst(self.infcx.tcx, substs); if let ty::RegionKind::ReStatic = r { diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 5aad7523c8903..fb9820e853f8f 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -1014,7 +1014,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } self.prove_predicate( - ty::PredicateAtom::WellFormed(inferred_ty.into()).to_predicate(self.tcx()), + ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()), Locations::All(span), ConstraintCategory::TypeAnnotation, ); @@ -1266,7 +1266,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { obligations.obligations.push(traits::Obligation::new( ObligationCause::dummy(), param_env, - ty::PredicateAtom::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx), + ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx), )); obligations.add( infcx @@ -1611,7 +1611,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_call_dest(body, term, &sig, destination, term_location); self.prove_predicates( - sig.inputs_and_output.iter().map(|ty| ty::PredicateAtom::WellFormed(ty.into())), + sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())), term_location.to_locations(), ConstraintCategory::Boring, ); @@ -2694,7 +2694,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { category: ConstraintCategory, ) { self.prove_predicates( - Some(ty::PredicateAtom::Trait( + Some(ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref }, hir::Constness::NotConst, )), diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index d1c07d1051d2f..88b2378cd06e7 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -411,24 +411,24 @@ impl Validator<'mir, 'tcx> { loop { let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { - match predicate.skip_binders() { - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::Projection(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, - ty::PredicateAtom::ObjectSafe(_) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, + ty::PredicateKind::ObjectSafe(_) => { bug!("object safe predicate on function: {:#?}", predicate) } - ty::PredicateAtom::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { bug!("closure kind predicate on function: {:#?}", predicate) } - ty::PredicateAtom::Subtype(_) => { + ty::PredicateKind::Subtype(_) => { bug!("subtype predicate on function: {:#?}", predicate) } - ty::PredicateAtom::Trait(pred, constness) => { + ty::PredicateKind::Trait(pred, constness) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/compiler/rustc_mir/src/transform/function_item_references.rs b/compiler/rustc_mir/src/transform/function_item_references.rs index 7c8c349da1d6c..8d02ac6d9b774 100644 --- a/compiler/rustc_mir/src/transform/function_item_references.rs +++ b/compiler/rustc_mir/src/transform/function_item_references.rs @@ -5,7 +5,7 @@ use rustc_middle::mir::*; use rustc_middle::ty::{ self, subst::{GenericArgKind, Subst, SubstsRef}, - PredicateAtom, Ty, TyCtxt, TyS, + PredicateKind, Ty, TyCtxt, TyS, }; use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES; use rustc_span::{symbol::sym, Span}; @@ -105,7 +105,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { let param_env = self.tcx.param_env(def_id); let bounds = param_env.caller_bounds(); for bound in bounds { - if let Some(bound_ty) = self.is_pointer_trait(&bound.skip_binders()) { + if let Some(bound_ty) = self.is_pointer_trait(&bound.kind().skip_binder()) { // Get the argument types as they appear in the function signature. let arg_defs = self.tcx.fn_sig(def_id).skip_binder().inputs(); for (arg_num, arg_def) in arg_defs.iter().enumerate() { @@ -131,8 +131,8 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { } /// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type. - fn is_pointer_trait(&self, bound: &PredicateAtom<'tcx>) -> Option> { - if let ty::PredicateAtom::Trait(predicate, _) = bound { + fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option> { + if let ty::PredicateKind::Trait(predicate, _) = bound { if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) { Some(predicate.trait_ref.self_ty()) } else { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index fb007c406bcfa..66206ca46c3a7 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -100,19 +100,19 @@ where } fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { - match predicate.skip_binders() { - ty::PredicateAtom::Trait(ty::TraitPredicate { trait_ref }, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => { self.visit_trait(trait_ref) } - ty::PredicateAtom::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { + ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { ty.visit_with(self)?; self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx())) } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => { ty.visit_with(self) } - ty::PredicateAtom::RegionOutlives(..) => ControlFlow::CONTINUE, - ty::PredicateAtom::ConstEvaluatable(..) + ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE, + ty::PredicateKind::ConstEvaluatable(..) if self.def_id_visitor.tcx().features().const_evaluatable_checked => { // FIXME(const_evaluatable_checked): If the constant used here depends on a diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index f5bc90e6f9621..25ba489032bf1 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -1153,7 +1153,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { debug!("instantiate_opaque_types: ty_var={:?}", ty_var); for predicate in &bounds { - if let ty::PredicateAtom::Projection(projection) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() { if projection.ty.references_error() { // No point on adding these obligations since there's a type error involved. return ty_var; @@ -1251,18 +1251,18 @@ crate fn required_region_bounds( traits::elaborate_predicates(tcx, predicates) .filter_map(|obligation| { debug!("required_region_bounds(obligation={:?})", obligation); - match obligation.predicate.skip_binders() { - ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::Trait(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::RegionOutlives(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => None, - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => { + match obligation.predicate.kind().skip_binder() { + 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ref t, ref r)) => { // Search for a bound of the form `erased_self_ty // : 'a`, but be wary of something like `for<'a> // erased_self_ty : 'a` (we interpret a diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index f8fe141746fdb..6593c1000f283 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -414,9 +414,9 @@ impl AutoTraitFinder<'tcx> { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { if let ( - ty::PredicateAtom::Trait(new_trait, _), - ty::PredicateAtom::Trait(old_trait, _), - ) = (new_pred.skip_binders(), old_pred.skip_binders()) + ty::PredicateKind::Trait(new_trait, _), + ty::PredicateKind::Trait(old_trait, _), + ) = (new_pred.kind().skip_binder(), old_pred.kind().skip_binder()) { if new_trait.def_id() == old_trait.def_id() { let new_substs = new_trait.trait_ref.substs; @@ -633,16 +633,16 @@ impl AutoTraitFinder<'tcx> { // We check this by calling is_of_param on the relevant types // from the various possible predicates - let bound_predicate = predicate.bound_atom(); + let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(p, _) => { + ty::PredicateKind::Trait(p, _) => { // Add this to `predicates` so that we end up calling `select` // with it. If this predicate ends up being unimplemented, // then `evaluate_predicates` will handle adding it the `ParamEnv` // if possible. predicates.push_back(bound_predicate.rebind(p)); } - ty::PredicateAtom::Projection(p) => { + ty::PredicateKind::Projection(p) => { let p = bound_predicate.rebind(p); debug!( "evaluate_nested_obligations: examining projection predicate {:?}", @@ -772,13 +772,13 @@ impl AutoTraitFinder<'tcx> { } } } - ty::PredicateAtom::RegionOutlives(binder) => { + ty::PredicateKind::RegionOutlives(binder) => { let binder = bound_predicate.rebind(binder); if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() { return false; } } - ty::PredicateAtom::TypeOutlives(binder) => { + ty::PredicateKind::TypeOutlives(binder) => { let binder = bound_predicate.rebind(binder); match ( binder.no_bound_vars(), @@ -801,7 +801,7 @@ impl AutoTraitFinder<'tcx> { _ => {} }; } - ty::PredicateAtom::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { let evaluate = |c: &'tcx ty::Const<'tcx>| { if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val { match select.infcx().const_eval_resolve( diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 370ad577170ba..ad229e03b0b6b 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -41,8 +41,8 @@ pub fn is_const_evaluatable<'cx, 'tcx>( // We are looking at a generic abstract constant. Some(ct) => { for pred in param_env.caller_bounds() { - match pred.skip_binders() { - ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => { + match pred.kind().skip_binder() { + ty::PredicateKind::ConstEvaluatable(b_def, b_substs) => { debug!( "is_const_evaluatable: caller_bound={:?}, {:?}", b_def, b_substs diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 795cf2e19decc..75a1a237570a4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -256,9 +256,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { return; } - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _) => { let trait_predicate = bound_predicate.rebind(trait_predicate); let trait_predicate = self.resolve_vars_if_possible(trait_predicate); @@ -517,14 +517,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err } - ty::PredicateAtom::Subtype(predicate) => { + ty::PredicateKind::Subtype(predicate) => { // Errors for Subtype predicates show up as // `FulfillmentErrorCode::CodeSubtypeError`, // not selection error. span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate) } - ty::PredicateAtom::RegionOutlives(predicate) => { + ty::PredicateKind::RegionOutlives(predicate) => { let predicate = bound_predicate.rebind(predicate); let predicate = self.resolve_vars_if_possible(predicate); let err = self @@ -541,7 +541,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::PredicateAtom::Projection(..) | ty::PredicateAtom::TypeOutlives(..) => { + ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => { let predicate = self.resolve_vars_if_possible(obligation.predicate); struct_span_err!( self.tcx.sess, @@ -552,12 +552,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::PredicateAtom::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::PredicateAtom::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( @@ -617,7 +617,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { return; } - ty::PredicateAtom::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 @@ -635,7 +635,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } - ty::PredicateAtom::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Errors for `ConstEvaluatable` predicates show up as // `SelectionError::ConstEvalFailure`, // not `Unimplemented`. @@ -646,7 +646,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::PredicateAtom::ConstEquate(..) => { + ty::PredicateKind::ConstEquate(..) => { // Errors for `ConstEquate` predicates show up as // `SelectionError::ConstEvalFailure`, // not `Unimplemented`. @@ -657,7 +657,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => span_bug!( + ty::PredicateKind::TypeWellFormedFromEnv(..) => span_bug!( span, "TypeWellFormedFromEnv predicate should only exist in the environment" ), @@ -1069,9 +1069,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { } // FIXME: It should be possible to deal with `ForAll` in a cleaner way. - let bound_error = error.bound_atom(); - let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) { - (ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => { + let bound_error = error.kind(); + let (cond, error) = match (cond.kind().skip_binder(), bound_error.skip_binder()) { + (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => { (cond, bound_error.rebind(error)) } _ => { @@ -1081,8 +1081,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { }; for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) { - let bound_predicate = obligation.predicate.bound_atom(); - if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() { + let bound_predicate = obligation.predicate.kind(); + if let ty::PredicateKind::Trait(implication, _) = bound_predicate.skip_binder() { let error = error.to_poly_trait_ref(); let implication = bound_predicate.rebind(implication.trait_ref); // FIXME: I'm just not taking associated types at all here. @@ -1162,8 +1162,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // // this can fail if the problem was higher-ranked, in which // cause I have no idea for a good error message. - let bound_predicate = predicate.bound_atom(); - if let ty::PredicateAtom::Projection(data) = bound_predicate.skip_binder() { + let bound_predicate = predicate.kind(); + if let ty::PredicateKind::Projection(data) = bound_predicate.skip_binder() { let mut selcx = SelectionContext::new(self); let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1452,9 +1452,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { return; } - let bound_predicate = predicate.bound_atom(); + let bound_predicate = predicate.kind(); let mut err = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(data, _) => { + ty::PredicateKind::Trait(data, _) => { let trait_ref = bound_predicate.rebind(data.trait_ref); debug!("trait_ref {:?}", trait_ref); @@ -1559,7 +1559,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { err } - ty::PredicateAtom::WellFormed(arg) => { + ty::PredicateKind::WellFormed(arg) => { // Same hacky approach as above to avoid deluging user // with error messages. if arg.references_error() || self.tcx.sess.has_errors() { @@ -1569,7 +1569,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { self.emit_inference_failure_err(body_id, span, arg, ErrorCode::E0282) } - ty::PredicateAtom::Subtype(data) => { + ty::PredicateKind::Subtype(data) => { if data.references_error() || self.tcx.sess.has_errors() { // no need to overload user in such cases return; @@ -1579,7 +1579,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { assert!(a.is_ty_var() && b.is_ty_var()); self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282) } - ty::PredicateAtom::Projection(data) => { + ty::PredicateKind::Projection(data) => { let trait_ref = bound_predicate.rebind(data).to_poly_trait_ref(self.tcx); let self_ty = trait_ref.skip_binder().self_ty(); let ty = data.ty; @@ -1709,9 +1709,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { obligation: &PredicateObligation<'tcx>, ) { let (pred, item_def_id, span) = - match (obligation.predicate.skip_binders(), obligation.cause.code.peel_derives()) { + match (obligation.predicate.kind().skip_binder(), obligation.cause.code.peel_derives()) + { ( - ty::PredicateAtom::Trait(pred, _), + ty::PredicateKind::Trait(pred, _), &ObligationCauseCode::BindingObligation(item_def_id, span), ) => (pred, item_def_id, span), _ => return, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 565b8d37868f8..1830aaa4471a6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1292,8 +1292,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // the type. The last generator (`outer_generator` below) has information about where the // bound was introduced. At least one generator should be present for this diagnostic to be // modified. - let (mut trait_ref, mut target_ty) = match obligation.predicate.skip_binders() { - ty::PredicateAtom::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())), + let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())), _ => (None, None), }; let mut generator = None; diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 86c5209354c85..d4ced20f86319 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -345,13 +345,13 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); - let binder = obligation.predicate.bound_atom(); - if binder.skip_binder().has_escaping_bound_vars() { - match binder.skip_binder() { + let binder = obligation.predicate.kind(); + match binder.no_bound_vars() { + None => match binder.skip_binder() { // Evaluation will discard candidates using the leak check. // This means we need to pass it the bound version of our // predicate. - ty::PredicateAtom::Trait(trait_ref, _constness) => { + ty::PredicateKind::Trait(trait_ref, _constness) => { let trait_obligation = obligation.with(binder.rebind(trait_ref)); self.process_trait_obligation( @@ -360,7 +360,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { &mut pending_obligation.stalled_on, ) } - ty::PredicateAtom::Projection(data) => { + ty::PredicateKind::Projection(data) => { let project_obligation = obligation.with(binder.rebind(data)); self.process_projection_obligation( @@ -368,26 +368,25 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { &mut pending_obligation.stalled_on, ) } - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::ObjectSafe(_) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::ObjectSafe(_) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => { let pred = infcx.replace_bound_vars_with_placeholders(binder); ProcessResult::Changed(mk_pending(vec![ obligation.with(pred.to_predicate(self.selcx.tcx())), ])) } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("TypeWellFormedFromEnv is only used for Chalk") } - } - } else { - match binder.skip_binder() { - ty::PredicateAtom::Trait(data, _) => { + }, + Some(pred) => match pred { + ty::PredicateKind::Trait(data, _) => { let trait_obligation = obligation.with(Binder::dummy(data)); self.process_trait_obligation( @@ -397,14 +396,14 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ) } - ty::PredicateAtom::RegionOutlives(data) => { + ty::PredicateKind::RegionOutlives(data) => { match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) { Ok(()) => ProcessResult::Changed(vec![]), Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)), } } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => { if self.register_region_obligations { self.selcx.infcx().register_region_obligation_with_cause( t_a, @@ -415,7 +414,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ProcessResult::Changed(vec![]) } - ty::PredicateAtom::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(Binder::dummy(*data)); self.process_projection_obligation( @@ -424,7 +423,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ) } - ty::PredicateAtom::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 { @@ -432,7 +431,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateAtom::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) { @@ -445,7 +444,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateAtom::WellFormed(arg) => { + ty::PredicateKind::WellFormed(arg) => { match wf::obligations( self.selcx.infcx(), obligation.param_env, @@ -463,7 +462,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateAtom::Subtype(subtype) => { + ty::PredicateKind::Subtype(subtype) => { match self.selcx.infcx().subtype_predicate( &obligation.cause, obligation.param_env, @@ -489,7 +488,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match const_evaluatable::is_const_evaluatable( self.selcx.infcx(), def_id, @@ -509,7 +508,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateAtom::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { debug!(?c1, ?c2, "equating consts"); if self.selcx.tcx().features().const_evaluatable_checked { // FIXME: we probably should only try to unify abstract constants @@ -595,10 +594,10 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("TypeWellFormedFromEnv is only used for Chalk") } - } + }, } } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 9c894e99a389a..dbc40a2eb9662 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -324,7 +324,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| { - matches!(predicate.skip_binders(), ty::PredicateAtom::TypeOutlives(..)) + matches!(predicate.kind().skip_binder(), ty::PredicateKind::TypeOutlives(..)) }) .collect(); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 8b6e30f34fd4a..a9723611f8113 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -273,12 +273,12 @@ fn predicate_references_self( ) -> Option { let self_ty = tcx.types.self_param; let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into()); - match predicate.skip_binders() { - ty::PredicateAtom::Trait(ref data, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(ref data, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None } } - ty::PredicateAtom::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 @@ -300,15 +300,15 @@ fn predicate_references_self( None } } - ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::TypeOutlives(..) - | ty::PredicateAtom::RegionOutlives(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, } } @@ -328,20 +328,20 @@ 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.skip_binders() { - ty::PredicateAtom::Trait(ref trait_pred, _) => { + match obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(ref trait_pred, _) => { trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } - ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::RegionOutlives(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::TypeOutlives(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => false, } }) } @@ -843,7 +843,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>( } fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow { - if let ty::PredicateAtom::ConstEvaluatable(def, substs) = pred.skip_binders() { + if let ty::PredicateKind::ConstEvaluatable(def, substs) = pred.kind().skip_binder() { // FIXME(const_evaluatable_checked): We should probably deduplicate the logic for // `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to // take a `ty::Const` instead. diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index fa0526445c194..75ff93197126c 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -625,7 +625,7 @@ fn prune_cache_value_obligations<'a, 'tcx>( .obligations .iter() .filter(|obligation| { - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { // We found a `T: Foo` predicate, let's check // if `U` references any unresolved type @@ -636,7 +636,7 @@ fn prune_cache_value_obligations<'a, 'tcx>( // indirect obligations (e.g., we project to `?0`, // but we have `T: Foo` and `?1: Bar`). - ty::PredicateAtom::Projection(data) => { + ty::PredicateKind::Projection(data) => { infcx.unresolved_type_vars(&bound_predicate.rebind(data.ty)).is_some() } @@ -917,8 +917,8 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( let infcx = selcx.infcx(); for predicate in env_predicates { debug!(?predicate); - let bound_predicate = predicate.bound_atom(); - if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() { + let bound_predicate = predicate.kind(); + if let ty::PredicateKind::Projection(data) = predicate.kind().skip_binder() { let data = bound_predicate.rebind(data); let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs index 93ddcb6855400..de538c62c5e39 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs @@ -15,7 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // `&T`, accounts for about 60% percentage of the predicates // we have to prove. No need to canonicalize and all that for // such cases. - if let ty::PredicateAtom::Trait(trait_ref, _) = key.value.predicate.skip_binders() { + if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind().skip_binder() { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.self_ty().is_trivially_sized(tcx) { diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 030c29171a153..3015188fd447a 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -432,7 +432,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .predicates .into_iter() { - if let ty::PredicateAtom::Trait(..) = super_trait.skip_binders() { + if let ty::PredicateKind::Trait(..) = super_trait.kind().skip_binder() { let normalized_super_trait = normalize_with_depth_to( self, obligation.param_env, @@ -641,7 +641,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.push(Obligation::new( obligation.cause.clone(), obligation.param_env, - ty::PredicateAtom::ClosureKind(closure_def_id, substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, substs, kind) .to_predicate(self.tcx()), )); } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 8ca540fc8933c..614a551004ecf 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -454,16 +454,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } let result = ensure_sufficient_stack(|| { - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(t, _) => { + ty::PredicateKind::Trait(t, _) => { let t = bound_predicate.rebind(t); debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(t); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } - ty::PredicateAtom::Subtype(p) => { + ty::PredicateKind::Subtype(p) => { let p = bound_predicate.rebind(p); // Does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { @@ -479,7 +479,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateAtom::WellFormed(arg) => match wf::obligations( + ty::PredicateKind::WellFormed(arg) => match wf::obligations( self.infcx, obligation.param_env, obligation.cause.body_id, @@ -494,12 +494,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { None => Ok(EvaluatedToAmbig), }, - ty::PredicateAtom::TypeOutlives(..) | ty::PredicateAtom::RegionOutlives(..) => { + ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => { // We do not consider region relationships when evaluating trait matches. Ok(EvaluatedToOkModuloRegions) } - ty::PredicateAtom::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if self.tcx().is_object_safe(trait_def_id) { Ok(EvaluatedToOk) } else { @@ -507,7 +507,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateAtom::Projection(data) => { + ty::PredicateKind::Projection(data) => { let data = bound_predicate.rebind(data); let project_obligation = obligation.with(data); match project::poly_project_and_unify_type(self, &project_obligation) { @@ -528,7 +528,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateAtom::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) { @@ -541,7 +541,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match const_evaluatable::is_const_evaluatable( self.infcx, def_id, @@ -555,7 +555,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateAtom::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { debug!(?c1, ?c2, "evaluate_predicate_recursively: equating consts"); let evaluate = |c: &'tcx ty::Const<'tcx>| { @@ -598,7 +598,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("TypeWellFormedFromEnv is only used for chalk") } } @@ -845,8 +845,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { - let result = match predicate.skip_binders() { - ty::PredicateAtom::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), + let result = match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; debug!(?predicate, ?result, "coinductive_predicate"); @@ -1174,8 +1174,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .iter() .enumerate() .filter_map(|(idx, bound)| { - let bound_predicate = bound.bound_atom(); - if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() { + let bound_predicate = bound.kind(); + if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { let bound = bound_predicate.rebind(pred.trait_ref); if self.infcx.probe(|_| { match self.match_normalize_trait_ref( diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index ef87071576da8..e6ef9b137d899 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -106,28 +106,28 @@ pub fn predicate_obligations<'a, 'tcx>( }; // It's ok to skip the binder here because wf code is prepared for it - match predicate.skip_binders() { - ty::PredicateAtom::Trait(t, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(t, _) => { wf.compute_trait_ref(&t.trait_ref, Elaborate::None); } - ty::PredicateAtom::RegionOutlives(..) => {} - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { + ty::PredicateKind::RegionOutlives(..) => {} + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { wf.compute(ty.into()); } - ty::PredicateAtom::Projection(t) => { + ty::PredicateKind::Projection(t) => { wf.compute_projection(t.projection_ty); wf.compute(t.ty.into()); } - ty::PredicateAtom::WellFormed(arg) => { + ty::PredicateKind::WellFormed(arg) => { wf.compute(arg); } - ty::PredicateAtom::ObjectSafe(_) => {} - ty::PredicateAtom::ClosureKind(..) => {} - ty::PredicateAtom::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => { + ty::PredicateKind::ObjectSafe(_) => {} + ty::PredicateKind::ClosureKind(..) => {} + ty::PredicateKind::Subtype(ty::SubtypePredicate { a, b, a_is_expected: _ }) => { wf.compute(a.into()); wf.compute(b.into()); } - ty::PredicateAtom::ConstEvaluatable(def, substs) => { + ty::PredicateKind::ConstEvaluatable(def, substs) => { let obligations = wf.nominal_obligations(def.did, substs); wf.out.extend(obligations); @@ -135,11 +135,11 @@ pub fn predicate_obligations<'a, 'tcx>( wf.compute(arg); } } - ty::PredicateAtom::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { wf.compute(c1.into()); wf.compute(c2.into()); } - ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("TypeWellFormedFromEnv is only used for Chalk") } } @@ -209,8 +209,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( }; // It is fine to skip the binder as we don't care about regions here. - match pred.skip_binders() { - ty::PredicateAtom::Projection(proj) => { + match pred.kind().skip_binder() { + ty::PredicateKind::Projection(proj) => { // The obligation comes not from the current `impl` nor the `trait` being implemented, // but rather from a "second order" obligation, where an associated type has a // projection coming from another associated type. See @@ -225,7 +225,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } } } - ty::PredicateAtom::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); @@ -343,7 +343,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { new_cause, depth, param_env, - ty::PredicateAtom::WellFormed(arg).to_predicate(tcx), + ty::PredicateKind::WellFormed(arg).to_predicate(tcx), ) }), ); @@ -393,7 +393,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause.clone(), depth, param_env, - ty::PredicateAtom::WellFormed(arg).to_predicate(tcx), + ty::PredicateKind::WellFormed(arg).to_predicate(tcx), ) }), ); @@ -436,7 +436,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let obligations = self.nominal_obligations(def.did, substs); self.out.extend(obligations); - let predicate = ty::PredicateAtom::ConstEvaluatable(def, substs) + let predicate = ty::PredicateKind::ConstEvaluatable(def, substs) .to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::with_depth( @@ -460,7 +460,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause, self.recursion_depth, self.param_env, - ty::PredicateAtom::WellFormed(resolved_constant.into()) + ty::PredicateKind::WellFormed(resolved_constant.into()) .to_predicate(self.tcx()), )); } @@ -547,7 +547,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause, depth, param_env, - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(rty, r)) + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r)) .to_predicate(self.tcx()), )); } @@ -637,7 +637,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause.clone(), depth, param_env, - ty::PredicateAtom::ObjectSafe(did).to_predicate(tcx), + ty::PredicateKind::ObjectSafe(did).to_predicate(tcx), ) })); } @@ -664,7 +664,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause, self.recursion_depth, param_env, - ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx()), + ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()), )); } else { // Yes, resolved, proceed with the result. diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 3a82ead08ab99..48d47054a4182 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -82,35 +82,35 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment chalk_ir::InEnvironment>> { let clauses = self.environment.into_iter().map(|predicate| { let (predicate, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, predicate.bound_atom()); + collect_bound_vars(interner, interner.tcx, predicate.kind()); let consequence = match predicate { - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => { + ty::PredicateKind::TypeWellFormedFromEnv(ty) => { chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))) } - ty::PredicateAtom::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv( + ty::PredicateKind::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv( chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)), ), - ty::PredicateAtom::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds( + ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives { a: predicate.0.lower_into(interner), b: predicate.1.lower_into(interner), }), ), - ty::PredicateAtom::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds( + ty::PredicateKind::TypeOutlives(predicate) => chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives { ty: predicate.0.lower_into(interner), lifetime: predicate.1.lower_into(interner), }), ), - ty::PredicateAtom::Projection(predicate) => chalk_ir::DomainGoal::Holds( + ty::PredicateKind::Projection(predicate) => chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)), ), - ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", predicate), + ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", predicate), }; let value = chalk_ir::ProgramClauseImplication { consequence, @@ -134,15 +134,15 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predicate<'tcx> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData> { let (predicate, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, self.bound_atom()); + collect_bound_vars(interner, interner.tcx, self.kind()); let value = match predicate { - ty::PredicateAtom::Trait(predicate, _) => { + ty::PredicateKind::Trait(predicate, _) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)), )) } - ty::PredicateAtom::RegionOutlives(predicate) => { + ty::PredicateKind::RegionOutlives(predicate) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives { a: predicate.0.lower_into(interner), @@ -150,7 +150,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi }), )) } - ty::PredicateAtom::TypeOutlives(predicate) => { + ty::PredicateKind::TypeOutlives(predicate) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives { ty: predicate.0.lower_into(interner), @@ -158,12 +158,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi }), )) } - ty::PredicateAtom::Projection(predicate) => { + ty::PredicateKind::Projection(predicate) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)), )) } - ty::PredicateAtom::WellFormed(arg) => match arg.unpack() { + ty::PredicateKind::WellFormed(arg) => match arg.unpack() { GenericArgKind::Type(ty) => match ty.kind() { // FIXME(chalk): In Chalk, a placeholder is WellFormed if it // `FromEnv`. However, when we "lower" Params, we don't update @@ -183,7 +183,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt), }, - ty::PredicateAtom::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal( + ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal( chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(t)), ), @@ -191,13 +191,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi // // We can defer this, but ultimately we'll want to express // some of these in terms of chalk operations. - ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => { + ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => { chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner)) } - ty::PredicateAtom::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal( + ty::PredicateKind::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal( chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))), ), }; @@ -568,34 +568,34 @@ impl<'tcx> LowerInto<'tcx, Option, ) -> Option>> { let (predicate, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, self.bound_atom()); + collect_bound_vars(interner, interner.tcx, self.kind()); let value = match predicate { - ty::PredicateAtom::Trait(predicate, _) => { + ty::PredicateKind::Trait(predicate, _) => { Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner))) } - ty::PredicateAtom::RegionOutlives(predicate) => { + ty::PredicateKind::RegionOutlives(predicate) => { Some(chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives { a: predicate.0.lower_into(interner), b: predicate.1.lower_into(interner), })) } - ty::PredicateAtom::TypeOutlives(predicate) => { + ty::PredicateKind::TypeOutlives(predicate) => { Some(chalk_ir::WhereClause::TypeOutlives(chalk_ir::TypeOutlives { ty: predicate.0.lower_into(interner), lifetime: predicate.1.lower_into(interner), })) } - ty::PredicateAtom::Projection(predicate) => { + ty::PredicateKind::Projection(predicate) => { Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner))) } - ty::PredicateAtom::WellFormed(_ty) => None, - - ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::WellFormed(_ty) => None, + + ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("unexpected predicate {}", &self) } }; @@ -699,28 +699,28 @@ impl<'tcx> LowerInto<'tcx, Option, ) -> Option>> { let (predicate, binders, _named_regions) = - collect_bound_vars(interner, interner.tcx, self.bound_atom()); + collect_bound_vars(interner, interner.tcx, self.kind()); match predicate { - ty::PredicateAtom::Trait(predicate, _) => Some(chalk_ir::Binders::new( + ty::PredicateKind::Trait(predicate, _) => Some(chalk_ir::Binders::new( binders, chalk_solve::rust_ir::InlineBound::TraitBound( predicate.trait_ref.lower_into(interner), ), )), - ty::PredicateAtom::Projection(predicate) => Some(chalk_ir::Binders::new( + ty::PredicateKind::Projection(predicate) => Some(chalk_ir::Binders::new( binders, chalk_solve::rust_ir::InlineBound::AliasEqBound(predicate.lower_into(interner)), )), - ty::PredicateAtom::TypeOutlives(_predicate) => None, - ty::PredicateAtom::WellFormed(_ty) => None, - - ty::PredicateAtom::RegionOutlives(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + ty::PredicateKind::TypeOutlives(_predicate) => None, + ty::PredicateKind::WellFormed(_ty) => None, + + ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => { bug!("unexpected predicate {}", &self) } } diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index cf7101ff7127a..90ba90259c32b 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -94,27 +94,27 @@ fn compute_implied_outlives_bounds<'tcx>( // region relationships. implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); - match obligation.predicate.bound_atom().no_bound_vars() { + match obligation.predicate.kind().no_bound_vars() { None => vec![], Some(pred) => match pred { - ty::PredicateAtom::Trait(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => vec![], - ty::PredicateAtom::WellFormed(arg) => { + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => vec![], + ty::PredicateKind::WellFormed(arg) => { wf_args.push(arg); vec![] } - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => { + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => { vec![OutlivesBound::RegionSubRegion(r_b, r_a)] } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => { let ty_a = infcx.resolve_vars_if_possible(ty_a); let mut components = smallvec![]; tcx.push_outlives_components(ty_a, &mut components); diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 4841e4286a994..1213e5539084e 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -46,16 +46,16 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( } fn not_outlives_predicate(p: &ty::Predicate<'tcx>) -> bool { - match p.skip_binders() { - ty::PredicateAtom::RegionOutlives(..) | ty::PredicateAtom::TypeOutlives(..) => false, - ty::PredicateAtom::Trait(..) - | ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => true, + match p.kind().skip_binder() { + 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => true, } } diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 0addde5c44c89..6304f696b00fa 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -140,7 +140,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { self.relate(self_ty, Variance::Invariant, impl_self_ty)?; self.prove_predicate( - ty::PredicateAtom::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()), + ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()), ); } @@ -155,7 +155,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { // them? This would only be relevant if some input // type were ill-formed but did not appear in `ty`, // which...could happen with normalization... - self.prove_predicate(ty::PredicateAtom::WellFormed(ty.into()).to_predicate(self.tcx())); + self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx())); Ok(()) } } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 64fefd82e06ab..bd1d9cc895fb0 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, ToPredicate, Ty, TyCtxt, WithConstness, + self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness, }; use rustc_session::CrateDisambiguator; use rustc_span::symbol::Symbol; @@ -378,7 +378,7 @@ fn well_formed_types_in_env<'tcx>( let input_clauses = inputs.into_iter().filter_map(|arg| { match arg.unpack() { GenericArgKind::Type(ty) => { - let binder = Binder::dummy(PredicateAtom::TypeWellFormedFromEnv(ty)); + let binder = Binder::dummy(PredicateKind::TypeWellFormedFromEnv(ty)); Some(tcx.mk_predicate(binder)) } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 9a2f69da32e81..059f9b41068c7 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1177,9 +1177,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { obligation.predicate ); - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _) => { let pred = bound_predicate.rebind(pred); associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) @@ -1188,7 +1188,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map(|item| item.def_id), ); } - ty::PredicateAtom::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { let pred = bound_predicate.rebind(pred); // A `Self` within the original bound will be substituted with a // `trait_object_dummy_self`, so check for that. diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 82fbbd3a77ea2..30e0e3eecd4a3 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -544,9 +544,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.infcx.instantiate_opaque_types(id, self.body_id, self.param_env, ty, span); let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty(); for o in impl_trait_ret_ty.obligations { - match o.predicate.bound_atom().skip_binder() { - ty::PredicateAtom::Trait(t, constness) => { - let pred = ty::PredicateAtom::Trait( + match o.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(t, constness) => { + let pred = ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref: ty::TraitRef { def_id: t.def_id(), diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index 7470c1a76a943..f34aaec10a9b9 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -192,9 +192,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligation.predicate ); - let bound_predicate = obligation.predicate.bound_atom(); - if let ty::PredicateAtom::Projection(proj_predicate) = - obligation.predicate.skip_binders() + let bound_predicate = obligation.predicate.kind(); + if let ty::PredicateKind::Projection(proj_predicate) = + obligation.predicate.kind().skip_binder() { // Given a Projection predicate, we can potentially infer // the complete signature. @@ -622,8 +622,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // where R is the return type we are expecting. This type `T` // will be our output. let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| { - let bound_predicate = obligation.predicate.bound_atom(); - if let ty::PredicateAtom::Projection(proj_predicate) = bound_predicate.skip_binder() { + let bound_predicate = obligation.predicate.kind(); + if let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() { self.deduce_future_output_from_projection( obligation.cause.span, bound_predicate.rebind(proj_predicate), diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 0d21c56f4cf4d..34ad8ec08984e 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -583,9 +583,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { while !queue.is_empty() { let obligation = queue.remove(0); debug!("coerce_unsized resolve step: {:?}", obligation); - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); let trait_pred = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(trait_pred, _) + ty::PredicateKind::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => { if unsize_did == trait_pred.def_id() { diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index be19919c0ea1f..4c3c4fd447058 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -226,13 +226,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // could be extended easily also to the other `Predicate`. let predicate_matches_closure = |p: Predicate<'tcx>| { let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); - let predicate = predicate.bound_atom(); - let p = p.bound_atom(); + let predicate = predicate.kind(); + let p = p.kind(); match (predicate.skip_binder(), p.skip_binder()) { - (ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => { + (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { relator.relate(predicate.rebind(a), p.rebind(b)).is_ok() } - (ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => { + (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { relator.relate(predicate.rebind(a), p.rebind(b)).is_ok() } _ => predicate == p, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 47799c95fc0a7..5a372c0aaabf1 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -542,7 +542,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::PredicateAtom::WellFormed(arg).to_predicate(self.tcx), + ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx), )); } @@ -764,21 +764,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .pending_obligations() .into_iter() .filter_map(move |obligation| { - let bound_predicate = obligation.predicate.bound_atom(); + let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Projection(data) => { + ty::PredicateKind::Projection(data) => { Some((bound_predicate.rebind(data).to_poly_trait_ref(self.tcx), obligation)) } - ty::PredicateAtom::Trait(data, _) => { + ty::PredicateKind::Trait(data, _) => { Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation)) } - ty::PredicateAtom::Subtype(..) => None, - ty::PredicateAtom::RegionOutlives(..) => None, - ty::PredicateAtom::TypeOutlives(..) => None, - ty::PredicateAtom::WellFormed(..) => None, - ty::PredicateAtom::ObjectSafe(..) => None, - ty::PredicateAtom::ConstEvaluatable(..) => None, - ty::PredicateAtom::ConstEquate(..) => None, + 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 @@ -787,8 +787,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // this closure yet; this is exactly why the other // code is looking for a self type of a unresolved // inference variable. - ty::PredicateAtom::ClosureKind(..) => None, - ty::PredicateAtom::TypeWellFormedFromEnv(..) => None, + ty::PredicateKind::ClosureKind(..) => None, + ty::PredicateKind::TypeWellFormedFromEnv(..) => None, } }) .filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root)) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 6177e39ba9e4c..6df9e3ab7dbe8 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -923,8 +923,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - if let ty::PredicateAtom::Trait(predicate, _) = - error.obligation.predicate.skip_binders() + if let ty::PredicateKind::Trait(predicate, _) = + error.obligation.predicate.kind().skip_binder() { // Collect the argument position for all arguments that could have caused this // `FulfillmentError`. @@ -974,8 +974,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(qpath) = &path.kind { if let hir::QPath::Resolved(_, path) = &qpath { for error in errors { - if let ty::PredicateAtom::Trait(predicate, _) = - error.obligation.predicate.skip_binders() + if let ty::PredicateKind::Trait(predicate, _) = + error.obligation.predicate.kind().skip_binder() { // If any of the type arguments in this path segment caused the // `FullfillmentError`, point at its span (#61860). diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index f635e0b6f931c..6d09043bd5033 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -194,8 +194,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { parent: None, predicates: tcx.arena.alloc_from_iter( self.param_env.caller_bounds().iter().filter_map(|predicate| { - match predicate.skip_binders() { - ty::PredicateAtom::Trait(data, _) if data.self_ty().is_param(index) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(data, _) if data.self_ty().is_param(index) => { // HACK(eddyb) should get the original `Span`. let span = tcx.def_span(def_id); Some((predicate, span)) diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index e604419f41378..af91514ba4bcd 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -478,8 +478,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) // We don't care about regions here. - .filter_map(|obligation| match obligation.predicate.skip_binders() { - ty::PredicateAtom::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { + .filter_map(|obligation| match obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { let span = predicates .predicates .iter() diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 8e13b3746992a..44343234117a4 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -399,7 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligations.push(traits::Obligation::new( cause, self.param_env, - ty::PredicateAtom::WellFormed(method_ty.into()).to_predicate(tcx), + ty::PredicateKind::WellFormed(method_ty.into()).to_predicate(tcx), )); let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig }; diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index d4631c465a3a7..be80b638260b7 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -795,9 +795,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty); let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| { - let bound_predicate = predicate.bound_atom(); + let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _) => { match *trait_predicate.trait_ref.self_ty().kind() { ty::Param(p) if p == param_ty => { Some(bound_predicate.rebind(trait_predicate.trait_ref)) @@ -805,16 +805,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { _ => None, } } - ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::RegionOutlives(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::TypeOutlives(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, } }); diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index e6bfa5e1497fe..c553fda49c308 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -582,8 +582,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut collect_type_param_suggestions = |self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| { // We don't care about regions here, so it's fine to skip the binder here. - if let (ty::Param(_), ty::PredicateAtom::Trait(p, _)) = - (self_ty.kind(), parent_pred.skip_binders()) + if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = + (self_ty.kind(), parent_pred.kind().skip_binder()) { if let ty::Adt(def, _) = p.trait_ref.self_ty().kind() { let node = def.did.as_local().map(|def_id| { @@ -637,9 +637,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; let mut format_pred = |pred: ty::Predicate<'tcx>| { - let bound_predicate = pred.bound_atom(); + let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { let pred = bound_predicate.rebind(pred); // `::Item = String`. let trait_ref = @@ -658,7 +658,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_span_label(trait_ref.self_ty(), &obligation, &quiet); Some((obligation, trait_ref.self_ty())) } - ty::PredicateAtom::Trait(poly_trait_ref, _) => { + ty::PredicateKind::Trait(poly_trait_ref, _) => { let p = poly_trait_ref.trait_ref; let self_ty = p.self_ty(); let path = p.print_only_trait_path(); @@ -992,11 +992,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // implementing a trait would be legal but is rejected // here). unsatisfied_predicates.iter().all(|(p, _)| { - match p.skip_binders() { + match p.kind().skip_binder() { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. - ty::PredicateAtom::Trait(t, _) => t.def_id() == info.def_id, - ty::PredicateAtom::Projection(p) => { + ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, + ty::PredicateKind::Projection(p) => { p.projection_ty.item_def_id == info.def_id } _ => false, diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 8177b363a5a5b..52276ed4beeaa 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -864,9 +864,9 @@ fn bounds_from_generic_predicates<'tcx>( let mut projections = vec![]; for (predicate, _) in predicates.predicates { debug!("predicate {:?}", predicate); - let bound_predicate = predicate.bound_atom(); + let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _) => { let entry = types.entry(trait_predicate.self_ty()).or_default(); let def_id = trait_predicate.def_id(); if Some(def_id) != tcx.lang_items().sized_trait() { @@ -875,7 +875,7 @@ fn bounds_from_generic_predicates<'tcx>( entry.push(trait_predicate.def_id()); } } - ty::PredicateAtom::Projection(projection_pred) => { + ty::PredicateKind::Projection(projection_pred) => { projections.push(bound_predicate.rebind(projection_pred)); } _ => {} diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 2c720ce025b0b..c90db4786e35f 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -532,7 +532,7 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::PredicateAtom::ConstEvaluatable( + ty::PredicateKind::ConstEvaluatable( ty::WithOptConstParam::unknown(discr_def_id.to_def_id()), discr_substs, ) diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 20b4aa1bc049f..d589989511db1 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -562,8 +562,8 @@ fn type_param_predicates( let extra_predicates = extend.into_iter().chain( icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true)) .into_iter() - .filter(|(predicate, _)| match predicate.skip_binders() { - ty::PredicateAtom::Trait(data, _) => data.self_ty().is_param(index), + .filter(|(predicate, _)| match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index), _ => false, }), ); @@ -1027,7 +1027,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::PredicateAtom::Trait(bound, _) = pred.skip_binders() { + if let ty::PredicateKind::Trait(bound, _) = pred.kind().skip_binder() { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -1946,7 +1946,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP } else { let span = bound_pred.bounded_ty.span; let re_root_empty = tcx.lifetimes.re_root_empty; - let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives( + let predicate = ty::Binder::bind(ty::PredicateKind::TypeOutlives( ty::OutlivesPredicate(ty, re_root_empty), )); predicates.insert((predicate.to_predicate(tcx), span)); @@ -1990,7 +1990,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP hir::GenericBound::Outlives(lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); predicates.insert(( - ty::Binder::bind(ty::PredicateAtom::TypeOutlives( + ty::Binder::bind(ty::PredicateKind::TypeOutlives( ty::OutlivesPredicate(ty, region), )) .to_predicate(tcx), @@ -2010,7 +2010,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP } _ => bug!(), }; - let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2)) + let pred = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)) .to_predicate(icx.tcx); (pred, span) @@ -2075,7 +2075,7 @@ fn const_evaluatable_predicates_of<'tcx>( if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val { let span = self.tcx.hir().span(c.hir_id); self.preds.insert(( - ty::PredicateAtom::ConstEvaluatable(def, substs).to_predicate(self.tcx), + ty::PredicateKind::ConstEvaluatable(def, substs).to_predicate(self.tcx), span, )); } @@ -2094,7 +2094,7 @@ fn const_evaluatable_predicates_of<'tcx>( fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> ControlFlow { if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val { self.preds.insert(( - ty::PredicateAtom::ConstEvaluatable(def, substs).to_predicate(self.tcx), + ty::PredicateKind::ConstEvaluatable(def, substs).to_predicate(self.tcx), self.span, )); } @@ -2180,12 +2180,12 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat .predicates .iter() .copied() - .filter(|(pred, _)| match pred.skip_binders() { - ty::PredicateAtom::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()), - ty::PredicateAtom::Projection(proj) => { + .filter(|(pred, _)| match pred.kind().skip_binder() { + ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()), + ty::PredicateKind::Projection(proj) => { !is_assoc_item_ty(proj.projection_ty.self_ty()) } - ty::PredicateAtom::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0), + ty::PredicateKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0), _ => true, }) .collect(); @@ -2214,7 +2214,8 @@ fn projection_ty_from_predicates( let (ty_def_id, item_def_id) = key; let mut projection_ty = None; for (predicate, _) in tcx.predicates_of(ty_def_id).predicates { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() + { if item_def_id == projection_predicate.projection_ty.item_def_id { projection_ty = Some(projection_predicate.projection_ty); break; @@ -2261,7 +2262,7 @@ fn predicates_from_bound<'tcx>( } hir::GenericBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); - let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region)) + let pred = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region)) .to_predicate(astconv.tcx()); vec![(pred, lifetime.span)] } diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index e596dd1a396c9..537a58328942b 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -36,13 +36,14 @@ fn associated_type_bounds<'tcx>( let trait_def_id = tcx.associated_item(assoc_item_def_id).container.id(); let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local()); - let bounds_from_parent = - trait_predicates.predicates.iter().copied().filter(|(pred, _)| match pred.skip_binders() { - ty::PredicateAtom::Trait(tr, _) => tr.self_ty() == item_ty, - ty::PredicateAtom::Projection(proj) => proj.projection_ty.self_ty() == item_ty, - ty::PredicateAtom::TypeOutlives(outlives) => outlives.0 == item_ty, + let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| { + match pred.kind().skip_binder() { + ty::PredicateKind::Trait(tr, _) => tr.self_ty() == item_ty, + ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty, + ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty, _ => false, - }); + } + }); let all_bounds = tcx .arena diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index e389fd4d9f00f..95670b9bdb983 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -183,7 +183,8 @@ pub fn setup_constraining_predicates<'tcx>( for j in i..predicates.len() { // Note that we don't have to care about binders here, // as the impl trait ref never contains any late-bound regions. - if let ty::PredicateAtom::Projection(projection) = predicates[j].0.skip_binders() { + if let ty::PredicateKind::Projection(projection) = predicates[j].0.kind().skip_binder() + { // Special case: watch out for some kind of sneaky attempt // to project out an associated type defined by this very // trait. diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 5db9ff9524de0..505d9a59d9c2f 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -198,7 +198,7 @@ fn unconstrained_parent_impl_substs<'tcx>( // the functions in `cgp` add the constrained parameters to a list of // unconstrained parameters. for (predicate, _) in impl_generic_predicates.predicates.iter() { - if let ty::PredicateAtom::Projection(proj) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(proj) = predicate.kind().skip_binder() { let projection_ty = proj.projection_ty; let projected_ty = proj.ty; @@ -360,13 +360,13 @@ fn check_predicates<'tcx>( fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, span: Span) { debug!("can_specialize_on(predicate = {:?})", predicate); - match predicate.skip_binders() { + match predicate.kind().skip_binder() { // Global predicates are either always true or always false, so we // are fine to specialize on. _ if predicate.is_global() => (), // We allow specializing on explicitly marked traits with no associated // items. - ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { if !matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::Marker) @@ -393,20 +393,20 @@ fn trait_predicate_kind<'tcx>( tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, ) -> Option { - match predicate.skip_binders() { - ty::PredicateAtom::Trait(pred, hir::Constness::NotConst) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } - ty::PredicateAtom::Trait(_, hir::Constness::Const) - | ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::Projection(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::Subtype(_) - | ty::PredicateAtom::ObjectSafe(_) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => 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(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, } } diff --git a/compiler/rustc_typeck/src/outlives/explicit.rs b/compiler/rustc_typeck/src/outlives/explicit.rs index ae336ccca457d..6e5be87928d59 100644 --- a/compiler/rustc_typeck/src/outlives/explicit.rs +++ b/compiler/rustc_typeck/src/outlives/explicit.rs @@ -29,8 +29,8 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { // process predicates and convert to `RequiredPredicates` entry, see below for &(predicate, span) in predicates.predicates { - match predicate.skip_binders() { - ty::PredicateAtom::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => { insert_outlives_predicate( tcx, (*ty).into(), @@ -40,7 +40,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { ) } - ty::PredicateAtom::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => { + ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => { insert_outlives_predicate( tcx, (*reg1).into(), @@ -50,15 +50,15 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { ) } - ty::PredicateAtom::Trait(..) - | ty::PredicateAtom::Projection(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => (), + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => (), } } diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index 8c92fc1744adc..e94b8450bfd05 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -30,9 +30,9 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec = predicates .iter() - .map(|(out_pred, _)| match out_pred.bound_atom().skip_binder() { - ty::PredicateAtom::RegionOutlives(p) => p.to_string(), - ty::PredicateAtom::TypeOutlives(p) => p.to_string(), + .map(|(out_pred, _)| match out_pred.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(p) => p.to_string(), + ty::PredicateKind::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), }) .collect(); @@ -85,12 +85,12 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica |(ty::OutlivesPredicate(kind1, region2), &span)| { match kind1.unpack() { GenericArgKind::Type(ty1) => Some(( - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2)) + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty1, region2)) .to_predicate(tcx), span, )), GenericArgKind::Lifetime(region1) => Some(( - ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate( + ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate( region1, region2, )) .to_predicate(tcx), diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 43fb53ba18fda..83114a72b8d5a 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -313,12 +313,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> FxHashSet { - let bound_predicate = pred.bound_atom(); + let bound_predicate = pred.kind(); let regions = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) } - ty::PredicateAtom::Projection(poly_proj_pred) => { + ty::PredicateKind::Projection(poly_proj_pred) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_proj_pred)) } _ => return FxHashSet::default(), @@ -463,8 +463,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .iter() .filter(|p| { !orig_bounds.contains(p) - || match p.skip_binders() { - ty::PredicateAtom::Trait(pred, _) => pred.def_id() == sized_trait, + || match p.kind().skip_binder() { + 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 35d93c58a9db4..bbc07e1011bc1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -465,20 +465,20 @@ impl Clean for hir::WherePredicate<'_> { impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option { - let bound_predicate = self.bound_atom(); + let bound_predicate = self.kind(); match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), - ty::PredicateAtom::RegionOutlives(pred) => pred.clean(cx), - ty::PredicateAtom::TypeOutlives(pred) => pred.clean(cx), - ty::PredicateAtom::Projection(pred) => Some(pred.clean(cx)), - - ty::PredicateAtom::Subtype(..) - | ty::PredicateAtom::WellFormed(..) - | ty::PredicateAtom::ObjectSafe(..) - | ty::PredicateAtom::ClosureKind(..) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => panic!("not user writable"), + ty::PredicateKind::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), + ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), + ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), + ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)), + + ty::PredicateKind::Subtype(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => panic!("not user writable"), } } } @@ -743,19 +743,19 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx .flat_map(|(p, _)| { let mut projection = None; let param_idx = (|| { - let bound_p = p.bound_atom(); + let bound_p = p.kind(); match bound_p.skip_binder() { - ty::PredicateAtom::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness) => { if let ty::Param(param) = pred.self_ty().kind() { return Some(param.index); } } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => { if let ty::Param(param) = ty.kind() { return Some(param.index); } } - ty::PredicateAtom::Projection(p) => { + ty::PredicateKind::Projection(p) => { if let ty::Param(param) = p.projection_ty.self_ty().kind() { projection = Some(bound_p.rebind(p)); return Some(param.index); @@ -1686,12 +1686,12 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|bound| { // Note: The substs of opaque types can contain unbound variables, // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. - let bound_predicate = bound.bound_atom(); + let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { - ty::PredicateAtom::Trait(tr, _constness) => { + ty::PredicateKind::Trait(tr, _constness) => { bound_predicate.rebind(tr.trait_ref) } - ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { + ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { if let Some(r) = reg.clean(cx) { regions.push(GenericBound::Outlives(r)); } @@ -1710,8 +1710,8 @@ impl<'tcx> Clean for Ty<'tcx> { let bounds: Vec<_> = bounds .iter() .filter_map(|bound| { - if let ty::PredicateAtom::Projection(proj) = - bound.bound_atom().skip_binder() + if let ty::PredicateKind::Projection(proj) = + bound.kind().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 16aaa9cfd20eb..d4d0a8ce24c7b 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -129,7 +129,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::PredicateAtom::Trait(pred, _) = pred.skip_binders() { + if let ty::PredicateKind::Trait(pred, _) = pred.kind().skip_binder() { if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None } } else { None diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index f9697afe40525..a3a38fad9a377 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{Opaque, PredicateAtom::Trait}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { &obligation, ); if let Trait(trait_pred, _) = - obligation.predicate.skip_binders() + obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 6e8102790a594..f7231bba17504 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -1697,7 +1697,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::Opaque(def_id, _) = *ret_ty.kind() { // one of the associated types must be Self for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { - if let ty::PredicateAtom::Projection(projection_predicate) = predicate.skip_binders() { + if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if contains_ty(projection_predicate.ty, self_ty) { return; diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 3e87ef03832d2..3b71f1b46e2ea 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,13 +115,10 @@ 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. - match obligation.predicate.bound_atom().skip_binder() { - ty::PredicateAtom::Trait(pred, _) if !pred.has_escaping_bound_vars() => { - if pred.def_id() == sized_trait { - return None; - } + match obligation.predicate.kind().no_bound_vars() { + Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => { Some(pred) - } + }, _ => None, } }) diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs index 2501635e7ef66..c6ae8b9b59837 100644 --- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs +++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{GenericPredicates, PredicateAtom, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{BytePos, Span}; @@ -42,7 +42,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateAtom::Trait(poly_trait_pred, _) = pred.skip_binders(); + if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; @@ -60,7 +60,7 @@ fn get_projection_pred<'tcx>( pred: TraitPredicate<'tcx>, ) -> Option> { generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ty::PredicateAtom::Projection(proj_pred) = proj_pred.skip_binders() { + if let ty::PredicateKind::Projection(proj_pred) = proj_pred.kind().skip_binder() { let projection_pred = cx.tcx.erase_late_bound_regions(ty::Binder::bind(proj_pred)); if projection_pred.projection_ty.substs == pred.trait_ref.substs { return Some(projection_pred); diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 3e39a47f1963d..4c707c4b90446 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -1470,7 +1470,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateAtom::Trait(trait_predicate, _) = predicate.skip_binders() { + if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { if must_use_attr(&cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } diff --git a/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs b/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs index 7cb7d0a26b65e..a482017afeb13 100644 --- a/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_lints/src/utils/qualify_min_const_fn.rs @@ -19,18 +19,18 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>) -> McfResult { loop { let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { - match predicate.skip_binders() { - ty::PredicateAtom::RegionOutlives(_) - | ty::PredicateAtom::TypeOutlives(_) - | ty::PredicateAtom::WellFormed(_) - | ty::PredicateAtom::Projection(_) - | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) - | ty::PredicateAtom::TypeWellFormedFromEnv(..) => continue, - ty::PredicateAtom::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), - ty::PredicateAtom::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), - ty::PredicateAtom::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateAtom::Trait(pred, _) => { + match predicate.kind().skip_binder() { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) + | ty::PredicateKind::TypeWellFormedFromEnv(..) => continue, + ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), + ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), + ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), + ty::PredicateKind::Trait(pred, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } From dcad9f1893d6bd4d09fe1c48ea4b500be1096031 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Thu, 7 Jan 2021 18:01:03 -0500 Subject: [PATCH 10/15] More review comments --- .../rustc_infer/src/infer/outlives/mod.rs | 6 ++---- compiler/rustc_middle/src/ty/context.rs | 14 +++++++------- compiler/rustc_middle/src/ty/mod.rs | 19 +++++++++---------- compiler/rustc_middle/src/ty/print/pretty.rs | 4 ---- .../rustc_middle/src/ty/structural_impls.rs | 4 ++-- src/librustdoc/clean/mod.rs | 2 -- 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index 13fc5b360a960..07c75d50d91da 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -6,7 +6,6 @@ pub mod verify; use rustc_middle::traits::query::OutlivesBound; use rustc_middle::ty; -use rustc_middle::ty::fold::TypeFoldable; pub fn explicit_outlives_bounds<'tcx>( param_env: ty::ParamEnv<'tcx>, @@ -16,9 +15,8 @@ pub fn explicit_outlives_bounds<'tcx>( .caller_bounds() .into_iter() .map(ty::Predicate::kind) - .map(ty::Binder::skip_binder) - .filter(|atom| !atom.has_escaping_bound_vars()) - .filter_map(move |atom| match atom { + .filter_map(ty::Binder::no_bound_vars) + .filter_map(move |kind| match kind { ty::PredicateKind::Projection(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ee4e7c8f0cc6f..3c53c42679522 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, binder: Binder>) -> &'tcx PredicateInner<'tcx> { + fn intern_predicate(&self, kind: Binder>) -> &'tcx PredicateInner<'tcx> { self.predicate - .intern(binder, |binder| { - let flags = super::flags::FlagComputation::for_predicate(binder); + .intern(kind, |kind| { + let flags = super::flags::FlagComputation::for_predicate(kind); let predicate_struct = PredicateInner { - binder, + kind, 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.binder == other.0.binder + self.0.kind == other.0.kind } } @@ -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.binder.hash(s) + self.0.kind.hash(s) } } impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { fn borrow<'a>(&'a self) -> &'a Binder> { - &self.0.binder + &self.0.kind } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index f8ae4a118db74..76d3bc7a3d51a 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> { - binder: Binder>, + kind: Binder>, flags: TypeFlags, /// See the comment for the corresponding field of [TyS]. outer_exclusive_binder: ty::DebruijnIndex, @@ -1060,21 +1060,21 @@ impl Hash for Predicate<'_> { impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { - /// Converts this to a `Binder>`. If the value was an - /// `Atom`, then it is not allowed to contain escaping bound vars. + /// Gets the inner `Binder>`. pub fn kind(self) -> Binder> { - self.inner.binder + self.inner.kind } - pub fn kind_ref(self) -> &'tcx Binder> { - &self.inner.binder + /// Like `kind` but returns a reference. Only needed because of encoding. + pub(super) fn kind_ref(self) -> &'tcx Binder> { + &self.inner.kind } } impl<'a, 'tcx> HashStable> for Predicate<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let PredicateInner { - ref binder, + ref kind, // The other fields just provide fast access to information that is // also contained in `kind`, so no need to hash them. @@ -1082,7 +1082,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { outer_exclusive_binder: _, } = self.inner; - binder.hash_stable(hcx, hasher); + kind.hash_stable(hcx, hasher); } } @@ -1221,7 +1221,7 @@ impl<'tcx> Predicate<'tcx> { let substs = trait_ref.skip_binder().substs; let pred = self.kind().skip_binder(); let new = pred.subst(tcx, substs); - if new != pred { ty::Binder::bind(new).to_predicate(tcx) } else { self } + tcx.reuse_or_mk_predicate(self, ty::Binder::bind(new)) } } @@ -1352,7 +1352,6 @@ impl ToPredicate<'tcx> for Binder> { impl ToPredicate<'tcx> for PredicateKind<'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(Binder::dummy(self)) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ed24f2c9bfb2d..8911de41c6d8e 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -623,10 +623,6 @@ pub trait PrettyPrinter<'tcx>: p!("impl"); for (predicate, _) in bounds { let predicate = predicate.subst(self.tcx(), substs); - // Note: We can't use `to_opt_poly_trait_ref` here as `predicate` - // may contain unbound variables. We therefore do this manually. - // - // FIXME(lcnr): Find out why exactly this is the case :) let bound_predicate = predicate.kind(); if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { let trait_ref = bound_predicate.rebind(pred.trait_ref); diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index ca625fddc99ab..44c173e356dfb 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -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.binder.fold_with(folder); + let new = self.inner.kind.fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.inner.binder.visit_with(visitor) + self.inner.kind.visit_with(visitor) } fn visit_with>(&self, visitor: &mut V) -> ControlFlow { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index bbc07e1011bc1..3ddb2adbf0aa7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1684,8 +1684,6 @@ impl<'tcx> Clean for Ty<'tcx> { let mut bounds = bounds .iter() .filter_map(|bound| { - // Note: The substs of opaque types can contain unbound variables, - // meaning that we have to use `ignore_quantifiers_with_unbound_vars` here. let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { ty::PredicateKind::Trait(tr, _constness) => { From f2ed9a3a8cc8d7972509143f2d8cb2a53e1a6b43 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Sat, 16 Jan 2021 19:17:59 -0500 Subject: [PATCH 11/15] Can't use EncodableWithShorthand for Predicate --- compiler/rustc_metadata/src/rmeta/encoder.rs | 6 ------ compiler/rustc_middle/src/ty/codec.rs | 21 ++----------------- compiler/rustc_middle/src/ty/mod.rs | 5 ----- .../src/ty/query/on_disk_cache.rs | 5 ----- 4 files changed, 2 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 58931bc5ff0a5..0b398c35db0ce 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -46,7 +46,6 @@ pub(super) struct EncodeContext<'a, 'tcx> { lazy_state: LazyState, type_shorthands: FxHashMap, usize>, - predicate_shorthands: FxHashMap, usize>, interpret_allocs: FxIndexSet, @@ -328,10 +327,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> { &mut self.type_shorthands } - fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize> { - &mut self.predicate_shorthands - } - fn encode_alloc_id( &mut self, alloc_id: &rustc_middle::mir::interpret::AllocId, @@ -2151,7 +2146,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata { tables: Default::default(), lazy_state: LazyState::NoNode, type_shorthands: Default::default(), - predicate_shorthands: Default::default(), source_file_cache, interpret_allocs: Default::default(), required_source_files, diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 6fa9c414bc043..380fb8172a758 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -43,19 +43,11 @@ 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() - } -} - pub trait TyEncoder<'tcx>: Encoder { const CLEAR_CROSS_CRATE: bool; fn position(&self) -> usize; fn type_shorthands(&mut self) -> &mut FxHashMap, usize>; - fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize>; fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>; } @@ -120,7 +112,7 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for Ty<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Predicate<'tcx> { fn encode(&self, e: &mut E) -> Result<(), E::Error> { - encode_with_shorthand(e, self, TyEncoder::predicate_shorthands) + self.kind().encode(e) } } @@ -220,16 +212,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for Ty<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Predicate<'tcx> { fn decode(decoder: &mut D) -> Result, D::Error> { - // Handle shorthands first, if we have an usize > 0x80. - let predicate_kind = if decoder.positioned_at_shorthand() { - let pos = decoder.read_usize()?; - assert!(pos >= SHORTHAND_OFFSET); - let shorthand = pos - SHORTHAND_OFFSET; - - decoder.with_position(shorthand, ty::Binder::>::decode) - } else { - ty::Binder::>::decode(decoder) - }?; + let predicate_kind = Decodable::decode(decoder)?; let predicate = decoder.tcx().mk_predicate(predicate_kind); Ok(predicate) } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 76d3bc7a3d51a..099c5aa84e511 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1064,11 +1064,6 @@ impl<'tcx> Predicate<'tcx> { pub fn kind(self) -> Binder> { self.inner.kind } - - /// Like `kind` but returns a reference. Only needed because of encoding. - pub(super) fn kind_ref(self) -> &'tcx Binder> { - &self.inner.kind - } } impl<'a, 'tcx> HashStable> for Predicate<'tcx> { diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index 6003509780a1d..914937134b47a 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -293,7 +293,6 @@ impl<'sess> OnDiskCache<'sess> { tcx, encoder, type_shorthands: Default::default(), - predicate_shorthands: Default::default(), interpret_allocs: Default::default(), source_map: CachingSourceMapView::new(tcx.sess.source_map()), file_to_file_index, @@ -989,7 +988,6 @@ struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { tcx: TyCtxt<'tcx>, encoder: &'a mut E, type_shorthands: FxHashMap, usize>, - predicate_shorthands: FxHashMap, usize>, interpret_allocs: FxIndexSet, source_map: CachingSourceMapView<'tcx>, file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>, @@ -1103,9 +1101,6 @@ where fn type_shorthands(&mut self) -> &mut FxHashMap, usize> { &mut self.type_shorthands } - fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize> { - &mut self.predicate_shorthands - } fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { let (index, _) = self.interpret_allocs.insert_full(*alloc_id); From 674735b109cdfb815c02b9b60fb65e5495f7cfe1 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Sun, 17 Jan 2021 02:49:30 -0500 Subject: [PATCH 12/15] Impl EncodableWithShorthand for PredicateKind --- compiler/rustc_metadata/src/rmeta/encoder.rs | 6 ++++ compiler/rustc_middle/src/ty/codec.rs | 31 +++++++++++++++++++ compiler/rustc_middle/src/ty/mod.rs | 2 +- .../src/ty/query/on_disk_cache.rs | 5 +++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0b398c35db0ce..5e2674254b295 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -46,6 +46,7 @@ pub(super) struct EncodeContext<'a, 'tcx> { lazy_state: LazyState, type_shorthands: FxHashMap, usize>, + predicate_shorthands: FxHashMap, usize>, interpret_allocs: FxIndexSet, @@ -327,6 +328,10 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> { &mut self.type_shorthands } + fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize> { + &mut self.predicate_shorthands + } + fn encode_alloc_id( &mut self, alloc_id: &rustc_middle::mir::interpret::AllocId, @@ -2146,6 +2151,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata { tables: Default::default(), lazy_state: LazyState::NoNode, type_shorthands: Default::default(), + predicate_shorthands: Default::default(), source_file_cache, interpret_allocs: Default::default(), required_source_files, diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 380fb8172a758..0aaba81819b00 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -43,11 +43,21 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> { } } +impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::PredicateKind<'tcx> { + type Variant = ty::PredicateKind<'tcx>; + + #[inline] + fn variant(&self) -> &Self::Variant { + self + } +} + pub trait TyEncoder<'tcx>: Encoder { const CLEAR_CROSS_CRATE: bool; fn position(&self) -> usize; fn type_shorthands(&mut self) -> &mut FxHashMap, usize>; + fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize>; fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>; } @@ -110,6 +120,12 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for Ty<'tcx> { } } +impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::PredicateKind<'tcx> { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { + encode_with_shorthand(e, self, TyEncoder::predicate_shorthands) + } +} + impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Predicate<'tcx> { fn encode(&self, e: &mut E) -> Result<(), E::Error> { self.kind().encode(e) @@ -210,6 +226,21 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for Ty<'tcx> { } } +impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::PredicateKind<'tcx> { + fn decode(decoder: &mut D) -> Result, D::Error> { + // Handle shorthands first, if we have an usize > 0x80. + if decoder.positioned_at_shorthand() { + let pos = decoder.read_usize()?; + assert!(pos >= SHORTHAND_OFFSET); + let shorthand = pos - SHORTHAND_OFFSET; + + decoder.with_position(shorthand, ty::PredicateKind::decode) + } else { + Ok(ty::PredicateKind::decode(decoder)?) + } + } +} + impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Predicate<'tcx> { fn decode(decoder: &mut D) -> Result, D::Error> { let predicate_kind = Decodable::decode(decoder)?; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 099c5aa84e511..88a2aac010c9a 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1081,7 +1081,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] #[derive(HashStable, TypeFoldable)] pub enum PredicateKind<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index 914937134b47a..cfe47004e01b6 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -293,6 +293,7 @@ impl<'sess> OnDiskCache<'sess> { tcx, encoder, type_shorthands: Default::default(), + predicate_shorthands: Default::default(), interpret_allocs: Default::default(), source_map: CachingSourceMapView::new(tcx.sess.source_map()), file_to_file_index, @@ -988,6 +989,7 @@ struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { tcx: TyCtxt<'tcx>, encoder: &'a mut E, type_shorthands: FxHashMap, usize>, + predicate_shorthands: FxHashMap, usize>, interpret_allocs: FxIndexSet, source_map: CachingSourceMapView<'tcx>, file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>, @@ -1101,6 +1103,9 @@ where fn type_shorthands(&mut self) -> &mut FxHashMap, usize> { &mut self.type_shorthands } + fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize> { + &mut self.predicate_shorthands + } fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { let (index, _) = self.interpret_allocs.insert_full(*alloc_id); From c76f47832a5086a76ea5f5f7636bfd35fcaee1d4 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Sun, 17 Jan 2021 04:13:51 -0500 Subject: [PATCH 13/15] Don't derive TyEncodable/TyDecodable for Binder --- compiler/rustc_middle/src/ty/codec.rs | 41 +++++++++++++++++++++------ compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 2 +- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 0aaba81819b00..a7b0ff45b976c 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -120,9 +120,9 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for Ty<'tcx> { } } -impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::PredicateKind<'tcx> { +impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Binder> { fn encode(&self, e: &mut E) -> Result<(), E::Error> { - encode_with_shorthand(e, self, TyEncoder::predicate_shorthands) + encode_with_shorthand(e, &self.skip_binder(), TyEncoder::predicate_shorthands) } } @@ -226,18 +226,18 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for Ty<'tcx> { } } -impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::PredicateKind<'tcx> { - fn decode(decoder: &mut D) -> Result, D::Error> { +impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Binder> { + fn decode(decoder: &mut D) -> Result>, D::Error> { // Handle shorthands first, if we have an usize > 0x80. - if decoder.positioned_at_shorthand() { + Ok(ty::Binder::bind(if decoder.positioned_at_shorthand() { let pos = decoder.read_usize()?; assert!(pos >= SHORTHAND_OFFSET); let shorthand = pos - SHORTHAND_OFFSET; - decoder.with_position(shorthand, ty::PredicateKind::decode) + decoder.with_position(shorthand, ty::PredicateKind::decode)? } else { - Ok(ty::PredicateKind::decode(decoder)?) - } + ty::PredicateKind::decode(decoder)? + })) } } @@ -471,3 +471,28 @@ macro_rules! implement_ty_decoder { } } } + +macro_rules! impl_binder_encode_decode { + ($($t:ty),+ $(,)?) => { + $( + impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Binder<$t> { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { + self.as_ref().skip_binder().encode(e) + } + } + impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Binder<$t> { + fn decode(decoder: &mut D) -> Result { + Ok(ty::Binder::bind(Decodable::decode(decoder)?)) + } + } + )* + } +} + +impl_binder_encode_decode! { + &'tcx ty::List>, + ty::FnSig<'tcx>, + ty::ExistentialPredicate<'tcx>, + ty::TraitRef<'tcx>, + Vec>, +} diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 88a2aac010c9a..099c5aa84e511 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1081,7 +1081,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateKind<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index d43c5135d90d5..cdf443975f428 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -955,7 +955,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { /// erase, or otherwise "discharge" these bound vars, we change the /// type from `Binder` to just `T` (see /// e.g., `liberate_late_bound_regions`). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct Binder(T); impl Binder { From d797a8549124b64410ae9e45392eac328aa71829 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Sun, 17 Jan 2021 12:32:05 -0500 Subject: [PATCH 14/15] Add comment about Encodable/Decodable impl --- compiler/rustc_middle/src/ty/sty.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index cdf443975f428..e08233b545d27 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -955,6 +955,8 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { /// erase, or otherwise "discharge" these bound vars, we change the /// type from `Binder` to just `T` (see /// e.g., `liberate_late_bound_regions`). +/// +/// `Decodable` and `Encodable` is implemented for `Binder` using the `impl_binder_encode_decode!` macro. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct Binder(T); From c4376ba24a488bf78003e35427d06e52b8b7479f Mon Sep 17 00:00:00 2001 From: Jack Huey <31162821+jackh726@users.noreply.github.com> Date: Sun, 17 Jan 2021 12:50:04 -0500 Subject: [PATCH 15/15] Whitespace and typo --- compiler/rustc_middle/src/ty/sty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index e08233b545d27..e53977b5eb978 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -956,7 +956,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { /// type from `Binder` to just `T` (see /// e.g., `liberate_late_bound_regions`). /// -/// `Decodable` and `Encodable` is implemented for `Binder` using the `impl_binder_encode_decode!` macro. +/// `Decodable` and `Encodable` are implemented for `Binder` using the `impl_binder_encode_decode!` macro. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct Binder(T);