From d398b54de6ae3b6f0e0880d33dd53ae5826cd4ba Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 16 Sep 2022 15:09:38 +0200 Subject: [PATCH] do not implement type traversal for `EarlyBinder` --- compiler/rustc_middle/src/ty/layout.rs | 5 ++++- compiler/rustc_middle/src/ty/structural_impls.rs | 12 ------------ compiler/rustc_middle/src/ty/sty.rs | 4 ++++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 042eeec3f46..13a6cf19009 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2770,7 +2770,10 @@ impl<'tcx> ty::Instance<'tcx> { // track of a polymorphization `ParamEnv` to allow normalizing later. let mut sig = match *ty.kind() { ty::FnDef(def_id, substs) => tcx - .normalize_erasing_regions(tcx.param_env(def_id), tcx.bound_fn_sig(def_id)) + .bound_fn_sig(def_id) + .map_bound(|fn_sig| { + tcx.normalize_erasing_regions(tcx.param_env(def_id), fn_sig) + }) .subst(tcx, substs), _ => unreachable!(), }; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index f5fd1f6ffaf..004fcffdc40 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -557,18 +557,6 @@ impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Box<[T]> { } } -impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::EarlyBinder { - fn try_fold_with>(self, folder: &mut F) -> Result { - self.try_map_bound(|ty| ty.try_fold_with(folder)) - } -} - -impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for ty::EarlyBinder { - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.as_ref().0.visit_with(visitor) - } -} - impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> { fn try_fold_with>(self, folder: &mut F) -> Result { folder.try_fold_binder(self) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 36e56085039..2d78c0c8656 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -919,6 +919,10 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { #[derive(Encodable, Decodable, HashStable)] pub struct EarlyBinder(pub T); +/// For early binders, you should first call `subst` before using any visitors. +impl<'tcx, T> !TypeFoldable<'tcx> for ty::EarlyBinder {} +impl<'tcx, T> !TypeVisitable<'tcx> for ty::EarlyBinder {} + impl EarlyBinder { pub fn as_ref(&self) -> EarlyBinder<&T> { EarlyBinder(&self.0)