diff options
| author | Michael Goulet <michael@errs.io> | 2024-05-26 20:03:47 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-05-26 20:04:05 -0400 |
| commit | bbcdb4fd3e4df3554e6d406a2f2e9e47114521f6 (patch) | |
| tree | 4c6258665a4b80409bea6c8582e0a8fad6cee202 /compiler/rustc_middle/src/ty | |
| parent | bdbbb6c6a718d4d196131aa16bafb60e850311d9 (diff) | |
| download | rust-bbcdb4fd3e4df3554e6d406a2f2e9e47114521f6.tar.gz rust-bbcdb4fd3e4df3554e6d406a2f2e9e47114521f6.zip | |
Give EarlyBinder a tcx parameter
We are gonna need it to uplift EarlyBinder
Diffstat (limited to 'compiler/rustc_middle/src/ty')
| -rw-r--r-- | compiler/rustc_middle/src/ty/abstract_const.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/adt.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/generic_args.rs | 80 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/generics.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/instance.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/normalize_erasing_regions.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/parameterized.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 4 |
12 files changed, 66 insertions, 52 deletions
diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs index dc46b470b6f..7fb5e9aadae 100644 --- a/compiler/rustc_middle/src/ty/abstract_const.rs +++ b/compiler/rustc_middle/src/ty/abstract_const.rs @@ -30,7 +30,8 @@ impl From<ErrorGuaranteed> for NotConstEvaluatable { TrivialTypeTraversalImpls! { NotConstEvaluatable } -pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>; +pub type BoundAbstractConst<'tcx> = + Result<Option<EarlyBinder<'tcx, ty::Const<'tcx>>>, ErrorGuaranteed>; impl<'tcx> TyCtxt<'tcx> { pub fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, ac: T) -> T { diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 48193754077..8e946bc8b31 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -579,7 +579,7 @@ impl<'tcx> AdtDef<'tcx> { /// Returns a type such that `Self: Sized` if and only if that type is `Sized`, /// or `None` if the type is always sized. - pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<Ty<'tcx>>> { + pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> { if self.is_struct() { tcx.adt_sized_constraint(self.did()) } else { None } } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 40a0dbeb2c2..3bf0fc44432 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -486,7 +486,10 @@ impl<'tcx> Const<'tcx> { } } -pub fn const_param_default(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Const<'_>> { +pub fn const_param_default<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: LocalDefId, +) -> ty::EarlyBinder<'tcx, Const<'tcx>> { let default_def_id = match tcx.hir_node_by_def_id(def_id) { hir::Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { default: Some(ac), .. }, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d138cd9ceb9..40871dd4ada 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -681,7 +681,7 @@ impl<'tcx> TyCtxt<'tcx> { /// In order to break cycles involving `AnonConst`, we need to set the expected type by side /// effect. However, we do not want this as a general capability, so this interface restricts /// to the only allowed case. - pub fn feed_anon_const_type(self, key: LocalDefId, value: ty::EarlyBinder<Ty<'tcx>>) { + pub fn feed_anon_const_type(self, key: LocalDefId, value: ty::EarlyBinder<'tcx, Ty<'tcx>>) { debug_assert_eq!(self.def_kind(key), DefKind::AnonConst); TyCtxtFeed { tcx: self, key }.type_of(value) } @@ -2746,7 +2746,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn impl_trait_ref( self, def_id: impl IntoQueryParam<DefId>, - ) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> { + ) -> Option<ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>> { Some(self.impl_trait_header(def_id)?.trait_ref) } diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index c7b15c64b08..6628eb247d6 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -584,48 +584,49 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx /// [`instantiate_identity`](EarlyBinder::instantiate_identity) or [`skip_binder`](EarlyBinder::skip_binder). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Encodable, Decodable, HashStable)] -pub struct EarlyBinder<T> { +pub struct EarlyBinder<'tcx, T> { value: T, + _tcx: PhantomData<&'tcx ()>, } /// For early binders, you should first call `instantiate` before using any visitors. -impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {} -impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {} +impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<'tcx, T> {} +impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for ty::EarlyBinder<'tcx, T> {} -impl<T> EarlyBinder<T> { - pub fn bind(value: T) -> EarlyBinder<T> { - EarlyBinder { value } +impl<'tcx, T> EarlyBinder<'tcx, T> { + pub fn bind(value: T) -> EarlyBinder<'tcx, T> { + EarlyBinder { value, _tcx: PhantomData } } - pub fn as_ref(&self) -> EarlyBinder<&T> { - EarlyBinder { value: &self.value } + pub fn as_ref(&self) -> EarlyBinder<'tcx, &T> { + EarlyBinder { value: &self.value, _tcx: PhantomData } } - pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<U> + pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<'tcx, U> where F: FnOnce(&T) -> U, { self.as_ref().map_bound(f) } - pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<U> + pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<'tcx, U> where F: FnOnce(T) -> U, { let value = f(self.value); - EarlyBinder { value } + EarlyBinder { value, _tcx: PhantomData } } - pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<U>, E> + pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<'tcx, U>, E> where F: FnOnce(T) -> Result<U, E>, { let value = f(self.value)?; - Ok(EarlyBinder { value }) + Ok(EarlyBinder { value, _tcx: PhantomData }) } - pub fn rebind<U>(&self, value: U) -> EarlyBinder<U> { - EarlyBinder { value } + pub fn rebind<U>(&self, value: U) -> EarlyBinder<'tcx, U> { + EarlyBinder { value, _tcx: PhantomData } } /// Skips the binder and returns the "bound" value. @@ -634,7 +635,7 @@ impl<T> EarlyBinder<T> { /// arguments of an `FnSig`). Otherwise, consider using /// [`instantiate_identity`](EarlyBinder::instantiate_identity). /// - /// To skip the binder on `x: &EarlyBinder<T>` to obtain `&T`, leverage + /// To skip the binder on `x: &EarlyBinder<'tcx, T>` to obtain `&T`, leverage /// [`EarlyBinder::as_ref`](EarlyBinder::as_ref): `x.as_ref().skip_binder()`. /// /// See also [`Binder::skip_binder`](super::Binder::skip_binder), which is @@ -644,13 +645,13 @@ impl<T> EarlyBinder<T> { } } -impl<T> EarlyBinder<Option<T>> { - pub fn transpose(self) -> Option<EarlyBinder<T>> { - self.value.map(|value| EarlyBinder { value }) +impl<'tcx, T> EarlyBinder<'tcx, Option<T>> { + pub fn transpose(self) -> Option<EarlyBinder<'tcx, T>> { + self.value.map(|value| EarlyBinder { value, _tcx: PhantomData }) } } -impl<'tcx, 's, I: IntoIterator> EarlyBinder<I> +impl<'tcx, 's, I: IntoIterator> EarlyBinder<'tcx, I> where I::Item: TypeFoldable<TyCtxt<'tcx>>, { @@ -682,7 +683,10 @@ where type Item = I::Item; fn next(&mut self) -> Option<Self::Item> { - Some(EarlyBinder { value: self.it.next()? }.instantiate(self.tcx, self.args)) + Some( + EarlyBinder { value: self.it.next()?, _tcx: PhantomData } + .instantiate(self.tcx, self.args), + ) } fn size_hint(&self) -> (usize, Option<usize>) { @@ -696,7 +700,10 @@ where I::Item: TypeFoldable<TyCtxt<'tcx>>, { fn next_back(&mut self) -> Option<Self::Item> { - Some(EarlyBinder { value: self.it.next_back()? }.instantiate(self.tcx, self.args)) + Some( + EarlyBinder { value: self.it.next_back()?, _tcx: PhantomData } + .instantiate(self.tcx, self.args), + ) } } @@ -707,7 +714,7 @@ where { } -impl<'tcx, 's, I: IntoIterator> EarlyBinder<I> +impl<'tcx, 's, I: IntoIterator> EarlyBinder<'tcx, I> where I::Item: Deref, <I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>, @@ -743,7 +750,9 @@ where type Item = <I::Item as Deref>::Target; fn next(&mut self) -> Option<Self::Item> { - self.it.next().map(|value| EarlyBinder { value: *value }.instantiate(self.tcx, self.args)) + self.it.next().map(|value| { + EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.tcx, self.args) + }) } fn size_hint(&self) -> (usize, Option<usize>) { @@ -758,9 +767,9 @@ where <I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>, { fn next_back(&mut self) -> Option<Self::Item> { - self.it - .next_back() - .map(|value| EarlyBinder { value: *value }.instantiate(self.tcx, self.args)) + self.it.next_back().map(|value| { + EarlyBinder { value: *value, _tcx: PhantomData }.instantiate(self.tcx, self.args) + }) } } @@ -772,21 +781,22 @@ where { } -pub struct EarlyBinderIter<T> { +pub struct EarlyBinderIter<'tcx, T> { t: T, + _tcx: PhantomData<&'tcx ()>, } -impl<T: IntoIterator> EarlyBinder<T> { - pub fn transpose_iter(self) -> EarlyBinderIter<T::IntoIter> { - EarlyBinderIter { t: self.value.into_iter() } +impl<'tcx, T: IntoIterator> EarlyBinder<'tcx, T> { + pub fn transpose_iter(self) -> EarlyBinderIter<'tcx, T::IntoIter> { + EarlyBinderIter { t: self.value.into_iter(), _tcx: PhantomData } } } -impl<T: Iterator> Iterator for EarlyBinderIter<T> { - type Item = EarlyBinder<T::Item>; +impl<'tcx, T: Iterator> Iterator for EarlyBinderIter<'tcx, T> { + type Item = EarlyBinder<'tcx, T::Item>; fn next(&mut self) -> Option<Self::Item> { - self.t.next().map(|value| EarlyBinder { value }) + self.t.next().map(|value| EarlyBinder { value, _tcx: PhantomData }) } fn size_hint(&self) -> (usize, Option<usize>) { @@ -794,7 +804,7 @@ impl<T: Iterator> Iterator for EarlyBinderIter<T> { } } -impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<T> { +impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<'tcx, T> { pub fn instantiate(self, tcx: TyCtxt<'tcx>, args: &[GenericArg<'tcx>]) -> T { let mut folder = ArgFolder { tcx, args, binders_passed: 0 }; self.value.fold_with(&mut folder) diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 1c4462fc1dc..7cb1a6f7273 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -88,7 +88,7 @@ impl GenericParamDef { pub fn default_value<'tcx>( &self, tcx: TyCtxt<'tcx>, - ) -> Option<EarlyBinder<ty::GenericArg<'tcx>>> { + ) -> Option<EarlyBinder<'tcx, ty::GenericArg<'tcx>>> { match self.kind { GenericParamDefKind::Type { has_default, .. } if has_default => { Some(tcx.type_of(self.def_id).map_bound(|t| t.into())) diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 7da7f69a954..a887047f62f 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -764,7 +764,7 @@ impl<'tcx> Instance<'tcx> { self.def.has_polymorphic_mir_body().then_some(self.args) } - pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<&T>) -> T + pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, &T>) -> T where T: TypeFoldable<TyCtxt<'tcx>> + Copy, { @@ -782,7 +782,7 @@ impl<'tcx> Instance<'tcx> { &self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - v: EarlyBinder<T>, + v: EarlyBinder<'tcx, T>, ) -> T where T: TypeFoldable<TyCtxt<'tcx>>, @@ -800,7 +800,7 @@ impl<'tcx> Instance<'tcx> { &self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - v: EarlyBinder<T>, + v: EarlyBinder<'tcx, T>, ) -> Result<T, NormalizationError<'tcx>> where T: TypeFoldable<TyCtxt<'tcx>>, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 79cfeb71d47..70cd833aea8 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -266,7 +266,7 @@ pub struct ImplHeader<'tcx> { #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct ImplTraitHeader<'tcx> { - pub trait_ref: ty::EarlyBinder<ty::TraitRef<'tcx>>, + pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>, pub polarity: ImplPolarity, pub safety: hir::Safety, } diff --git a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs index e2cfabfdafa..fb16cf5bd36 100644 --- a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs +++ b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs @@ -125,7 +125,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_args: GenericArgsRef<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: EarlyBinder<T>, + value: EarlyBinder<'tcx, T>, ) -> T where T: TypeFoldable<TyCtxt<'tcx>>, @@ -143,7 +143,7 @@ impl<'tcx> TyCtxt<'tcx> { self, param_args: GenericArgsRef<'tcx>, param_env: ty::ParamEnv<'tcx>, - value: EarlyBinder<T>, + value: EarlyBinder<'tcx, T>, ) -> Result<T, NormalizationError<'tcx>> where T: TypeFoldable<TyCtxt<'tcx>>, diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs index 571c6e918dc..f394b3c990c 100644 --- a/compiler/rustc_middle/src/ty/parameterized.rs +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -33,8 +33,8 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> { type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>; } -impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::EarlyBinder<T> { - type Value<'tcx> = ty::EarlyBinder<T::Value<'tcx>>; +impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::EarlyBinder<'static, T> { + type Value<'tcx> = ty::EarlyBinder<'tcx, T::Value<'tcx>>; } #[macro_export] diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 40f3db89df5..41b5e6d4dcc 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2055,7 +2055,7 @@ impl<'tcx> Ty<'tcx> { fn async_destructor_combinator( tcx: TyCtxt<'tcx>, lang_item: LangItem, - ) -> ty::EarlyBinder<Ty<'tcx>> { + ) -> ty::EarlyBinder<'tcx, Ty<'tcx>> { tcx.fn_sig(tcx.require_lang_item(lang_item, None)) .map_bound(|fn_sig| fn_sig.output().no_bound_vars().unwrap()) } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 5a3d90221eb..cacaa859d52 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -694,7 +694,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn coroutine_hidden_types( self, def_id: DefId, - ) -> impl Iterator<Item = ty::EarlyBinder<Ty<'tcx>>> { + ) -> impl Iterator<Item = ty::EarlyBinder<'tcx, Ty<'tcx>>> { let coroutine_layout = self.mir_coroutine_witnesses(def_id); coroutine_layout .as_ref() @@ -709,7 +709,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn bound_coroutine_hidden_types( self, def_id: DefId, - ) -> impl Iterator<Item = ty::EarlyBinder<ty::Binder<'tcx, Ty<'tcx>>>> { + ) -> impl Iterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> { let coroutine_layout = self.mir_coroutine_witnesses(def_id); coroutine_layout .as_ref() |
