diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 254d28d243ff2..6d4cbcf1bdfb1 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -52,7 +52,7 @@ impl<'tcx> UniverseInfo<'tcx> { pub(crate) fn report_erroneous_element( &self, mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, error_element: RegionElement<'tcx>, cause: ObligationCause<'tcx>, ) { @@ -152,7 +152,7 @@ pub(crate) trait TypeOpInfo<'tcx> { fn report_erroneous_element( &self, mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, error_element: RegionElement<'tcx>, cause: ObligationCause<'tcx>, ) { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 9c2b9139367a9..f85a7f901c8d2 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -111,7 +111,7 @@ pub(crate) enum RegionErrorKind<'tcx> { /// The region element that erroneously must be outlived by `longer_fr`. error_element: RegionElement<'tcx>, /// The placeholder region. - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, }, /// Any other lifetime error. diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 80f1098de85e7..75418f67a8f23 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -481,7 +481,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { pub(crate) fn placeholders_contained_in( &self, r: RegionVid, - ) -> impl Iterator> { + ) -> impl Iterator>> { let scc = self.constraint_sccs.scc(r); self.scc_values.placeholders_contained_in(scc) } @@ -1311,7 +1311,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn check_bound_universal_region( &self, longer_fr: RegionVid, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, errors_buffer: &mut RegionErrors<'tcx>, ) { debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,); diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 0063af25d781a..2e3b0527aa273 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -32,7 +32,7 @@ pub(crate) enum RegionElement<'tcx> { /// A placeholder (e.g., instantiated from a `for<'a> fn(&'a u32)` /// type). - PlaceholderRegion(ty::PlaceholderRegion<'tcx>), + PlaceholderRegion(ty::PlaceholderRegion>), } /// Records the CFG locations where each region is live. When we initially compute liveness, we use @@ -197,19 +197,22 @@ impl LivenessValues { #[derive(Debug, Default)] #[derive(Clone)] // FIXME(#146079) pub(crate) struct PlaceholderIndices<'tcx> { - indices: FxIndexSet>, + indices: FxIndexSet>>, } impl<'tcx> PlaceholderIndices<'tcx> { /// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion` - pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion<'tcx>) -> PlaceholderIndex { + pub(crate) fn insert( + &mut self, + placeholder: ty::PlaceholderRegion>, + ) -> PlaceholderIndex { let (index, _) = self.indices.insert_full(placeholder); index.into() } pub(crate) fn lookup_index( &self, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, ) -> PlaceholderIndex { self.indices.get_index_of(&placeholder).unwrap().into() } @@ -217,7 +220,7 @@ impl<'tcx> PlaceholderIndices<'tcx> { pub(crate) fn lookup_placeholder( &self, placeholder: PlaceholderIndex, - ) -> ty::PlaceholderRegion<'tcx> { + ) -> ty::PlaceholderRegion> { self.indices[placeholder.index()] } @@ -362,7 +365,7 @@ impl<'tcx, N: Idx> RegionValues<'tcx, N> { pub(crate) fn placeholders_contained_in( &self, r: N, - ) -> impl Iterator> { + ) -> impl Iterator>> { self.placeholders .row(r) .into_iter() @@ -417,7 +420,7 @@ impl ToElementIndex<'_> for RegionVid { } } -impl<'tcx> ToElementIndex<'tcx> for ty::PlaceholderRegion<'tcx> { +impl<'tcx> ToElementIndex<'tcx> for ty::PlaceholderRegion> { fn add_to_row(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool where Self: Into, ty::BoundRegion>>, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 220de046293a1..f3fcaf3de9d33 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -289,7 +289,7 @@ impl<'tcx> MirTypeckRegionConstraints<'tcx> { pub(crate) fn placeholder_region( &mut self, infcx: &InferCtxt<'tcx>, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, ) -> ty::Region<'tcx> { let placeholder_index = self.placeholder_indices.insert(placeholder); match self.placeholder_index_to_region.get(placeholder_index) { diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 045507ceb4b43..49748bab1f632 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -259,7 +259,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { #[instrument(skip(self), level = "debug")] fn next_placeholder_region( &mut self, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, ) -> ty::Region<'tcx> { let reg = self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder); diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 53567c6071e3c..f7676ded24bc1 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -465,7 +465,7 @@ pub enum NllRegionVariableOrigin<'tcx> { /// "Universal" instantiation of a higher-ranked region (e.g., /// from a `for<'a> T` binder). Meant to represent "any region". - Placeholder(ty::PlaceholderRegion<'tcx>), + Placeholder(ty::PlaceholderRegion>), Existential { name: Option, diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index f06f50785eccf..2bf3bfc1b7336 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -394,7 +394,7 @@ where &mut self, origin: infer::SubregionOrigin<'tcx>, region: ty::Region<'tcx>, - placeholder_ty: ty::PlaceholderType<'tcx>, + placeholder_ty: ty::PlaceholderType>, ) { let verify_bound = self .verify_bound diff --git a/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs b/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs index 4ef1ea5a1c4d9..c2a0d9be8b12f 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs @@ -105,7 +105,7 @@ struct LeakCheck<'a, 'tcx> { // is repurposed to store some placeholder `P` such that the weaker // condition `S: P` must hold. (This is true if `S: S1` transitively and `S1 // = P`.) - scc_placeholders: IndexVec>>, + scc_placeholders: IndexVec>>>, // For each SCC S, track the minimum universe that flows into it. Note that // this is both the minimum of the universes for every region that is a @@ -258,15 +258,15 @@ impl<'a, 'tcx> LeakCheck<'a, 'tcx> { fn placeholder_error( &self, - placeholder1: ty::PlaceholderRegion<'tcx>, - placeholder2: ty::PlaceholderRegion<'tcx>, + placeholder1: ty::PlaceholderRegion>, + placeholder2: ty::PlaceholderRegion>, ) -> TypeError<'tcx> { self.error(placeholder1, ty::Region::new_placeholder(self.tcx, placeholder2)) } fn error( &self, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, other_region: ty::Region<'tcx>, ) -> TypeError<'tcx> { debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region); diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index ae7481b5d1e76..0a9f483048561 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -125,7 +125,7 @@ pub struct Verify<'tcx> { #[derive(Copy, Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub enum GenericKind<'tcx> { Param(ty::ParamTy), - Placeholder(ty::PlaceholderType<'tcx>), + Placeholder(ty::PlaceholderType>), Alias(ty::AliasTy<'tcx>), } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 787ea5f9363d2..b57c7ae2cafc0 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -109,7 +109,7 @@ impl<'tcx> Const<'tcx> { #[inline] pub fn new_placeholder( tcx: TyCtxt<'tcx>, - placeholder: ty::PlaceholderConst<'tcx>, + placeholder: ty::PlaceholderConst>, ) -> Const<'tcx> { Const::new(tcx, ty::ConstKind::Placeholder(placeholder)) } @@ -195,7 +195,7 @@ impl<'tcx> rustc_type_ir::inherent::Const> for Const<'tcx> { Const::new_canonical_bound(tcx, var) } - fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<'tcx>) -> Self { + fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst>) -> Self { Const::new_placeholder(tcx, placeholder) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 471bd1d937e94..a2e6395f8497b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -145,10 +145,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type FnInputTys = &'tcx [Ty<'tcx>]; type ParamTy = ParamTy; - type BoundTy = ty::BoundTy; + //type BoundTy = ty::BoundTy; type Symbol = Symbol; - type PlaceholderTy = ty::PlaceholderType<'tcx>; + type PlaceholderTy = ty::PlaceholderType>; type ErrorGuaranteed = ErrorGuaranteed; type BoundExistentialPredicates = &'tcx List>; @@ -158,10 +158,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type Safety = hir::Safety; type Abi = ExternAbi; type Const = ty::Const<'tcx>; - type PlaceholderConst = ty::PlaceholderConst<'tcx>; + //type PlaceholderConst = ty::PlaceholderConst<'tcx>; type ParamConst = ty::ParamConst; - type BoundConst = ty::BoundConst; + //type BoundConst = ty::BoundConst; type ValueConst = ty::Value<'tcx>; type ExprConst = ty::Expr<'tcx>; type ValTree = ty::ValTree<'tcx>; @@ -170,7 +170,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type EarlyParamRegion = ty::EarlyParamRegion; type LateParamRegion = ty::LateParamRegion; type BoundRegion = ty::BoundRegion; - type PlaceholderRegion = ty::PlaceholderRegion<'tcx>; + type BoundRegionKind = ty::BoundRegionKind; + type BoundVariableKind = ty::BoundVariableKind; + type BoundTyKind = ty::BoundTyKind; + //type PlaceholderRegion = ty::PlaceholderRegion>; type RegionAssumptions = &'tcx ty::List>; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2021f175cd848..6dedbfad7ae4d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -900,99 +900,109 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> { } } -pub type PlaceholderRegion<'tcx> = ty::Placeholder, BoundRegion>; - -impl<'tcx> rustc_type_ir::inherent::PlaceholderLike> for PlaceholderRegion<'tcx> { - type Bound = BoundRegion; - - fn universe(self) -> UniverseIndex { - self.universe - } - - fn var(self) -> BoundVar { - self.bound.var - } - - fn with_updated_universe(self, ui: UniverseIndex) -> Self { - ty::Placeholder::new(ui, self.bound) - } - - fn new(ui: UniverseIndex, bound: BoundRegion) -> Self { - ty::Placeholder::new(ui, bound) - } - - fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self { - ty::Placeholder::new(ui, BoundRegion { var, kind: BoundRegionKind::Anon }) - } -} - -pub type PlaceholderType<'tcx> = ty::Placeholder, BoundTy>; - -impl<'tcx> rustc_type_ir::inherent::PlaceholderLike> for PlaceholderType<'tcx> { - type Bound = BoundTy; - - fn universe(self) -> UniverseIndex { - self.universe - } - - fn var(self) -> BoundVar { - self.bound.var - } - - fn with_updated_universe(self, ui: UniverseIndex) -> Self { - ty::Placeholder::new(ui, self.bound) - } - - fn new(ui: UniverseIndex, bound: BoundTy) -> Self { - ty::Placeholder::new(ui, bound) - } - - fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self { - ty::Placeholder::new(ui, BoundTy { var, kind: BoundTyKind::Anon }) - } -} - -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] -#[derive(TyEncodable, TyDecodable)] -pub struct BoundConst { - pub var: BoundVar, -} - -impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundConst { - fn var(self) -> BoundVar { - self.var - } - - fn assert_eq(self, var: ty::BoundVariableKind) { - var.expect_const() - } -} - -pub type PlaceholderConst<'tcx> = ty::Placeholder, BoundConst>; - -impl<'tcx> rustc_type_ir::inherent::PlaceholderLike> for PlaceholderConst<'tcx> { - type Bound = BoundConst; - - fn universe(self) -> UniverseIndex { - self.universe - } - - fn var(self) -> BoundVar { - self.bound.var - } - - fn with_updated_universe(self, ui: UniverseIndex) -> Self { - ty::Placeholder::new(ui, self.bound) - } - - fn new(ui: UniverseIndex, bound: BoundConst) -> Self { - ty::Placeholder::new(ui, bound) - } - - fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self { - ty::Placeholder::new(ui, BoundConst { var }) - } -} +//pub type PlaceholderRegion<'tcx> = ty::Placeholder, BoundRegion>; +// +//impl<'tcx> rustc_type_ir::inherent::PlaceholderLike, BoundRegion> +// for PlaceholderRegion<'tcx> +//{ +// type Bound = BoundRegion; +// +// fn universe(self) -> UniverseIndex { +// self.universe +// } +// +// fn var(self) -> BoundVar { +// self.bound.var +// } +// +// fn with_updated_universe(self, ui: UniverseIndex) -> Self { +// ty::Placeholder::new(ui, self.bound) +// } +// +// fn new(ui: UniverseIndex, bound: BoundRegion) -> Self { +// ty::Placeholder::new(ui, bound) +// } +// +// fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self { +// ty::Placeholder::new(ui, BoundRegion { var, kind: BoundRegionKind::Anon }) +// } +//} + +//pub type PlaceholderType<'tcx> = ty::Placeholder, BoundTy>; +// +//impl<'tcx> rustc_type_ir::inherent::PlaceholderLike, BoundTy> +// for PlaceholderType<'tcx> +//{ +// type Bound = BoundTy; +// +// fn universe(self) -> UniverseIndex { +// self.universe +// } +// +// fn var(self) -> BoundVar { +// self.bound.var +// } +// +// fn with_updated_universe(self, ui: UniverseIndex) -> Self { +// ty::Placeholder::new(ui, self.bound) +// } +// +// fn new(ui: UniverseIndex, bound: BoundTy) -> Self { +// ty::Placeholder::new(ui, bound) +// } +// +// fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self { +// ty::Placeholder::new(ui, BoundTy { var, kind: BoundTyKind::Anon }) +// } +//} + +//#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] +//#[derive(TyEncodable, TyDecodable)] +//pub struct BoundConst { +// pub var: BoundVar, +//} +// +//impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundConst { +// fn var(self) -> BoundVar { +// self.var +// } +// +// fn assert_eq(self, var: ty::BoundVariableKind) { +// var.expect_const() +// } +// +// fn new(var: BoundVar, _kind: BoundRegionKind) -> Self { +// Self { var } +// } +//} +// +//pub type PlaceholderConst<'tcx> = ty::Placeholder, BoundConst>; +// +//impl<'tcx> rustc_type_ir::inherent::PlaceholderLike, BoundConst> +// for PlaceholderConst<'tcx> +//{ +// type Bound = BoundConst; +// +// fn universe(self) -> UniverseIndex { +// self.universe +// } +// +// fn var(self) -> BoundVar { +// self.bound.var +// } +// +// fn with_updated_universe(self, ui: UniverseIndex) -> Self { +// ty::Placeholder::new(ui, self.bound) +// } +// +// fn new(ui: UniverseIndex, bound: BoundConst) -> Self { +// ty::Placeholder::new(ui, bound) +// } +// +// fn new_anon(ui: UniverseIndex, bound: BoundVar) -> Self { +// ty::Placeholder::new(ui, BoundConst { var }) +// } +//} pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo>; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c4f2917ad9e53..f4b00c1071cd4 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -3277,7 +3277,7 @@ define_print! { self.term.print(p)?; } - ty::PlaceholderType<'tcx> { + ty::PlaceholderType> { match self.bound.kind { ty::BoundTyKind::Anon => write!(p, "{self:?}")?, ty::BoundTyKind::Param(def_id) => match p.should_print_verbose() { diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index 61994d928decd..e5dc3a724fc85 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -99,7 +99,7 @@ impl<'tcx> Region<'tcx> { #[inline] pub fn new_placeholder( tcx: TyCtxt<'tcx>, - placeholder: ty::PlaceholderRegion<'tcx>, + placeholder: ty::PlaceholderRegion>, ) -> Region<'tcx> { tcx.intern_region(ty::RePlaceholder(placeholder)) } @@ -173,7 +173,10 @@ impl<'tcx> rustc_type_ir::inherent::Region> for Region<'tcx> { Region::new_canonical_bound(tcx, var) } - fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion<'tcx>) -> Self { + fn new_placeholder( + tcx: TyCtxt<'tcx>, + placeholder: ty::PlaceholderRegion>, + ) -> Self { Region::new_placeholder(tcx, placeholder) } @@ -469,37 +472,41 @@ pub enum BoundRegionKind { ClosureEnv, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] -#[derive(HashStable)] -pub struct BoundRegion { - pub var: BoundVar, - pub kind: BoundRegionKind, -} - -impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundRegion { - fn var(self) -> BoundVar { - self.var - } - - fn assert_eq(self, var: ty::BoundVariableKind) { - assert_eq!(self.kind, var.expect_region()) - } -} - -impl core::fmt::Debug for BoundRegion { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self.kind { - BoundRegionKind::Anon => write!(f, "{:?}", self.var), - BoundRegionKind::ClosureEnv => write!(f, "{:?}.Env", self.var), - BoundRegionKind::Named(def) => { - write!(f, "{:?}.Named({:?})", self.var, def) - } - BoundRegionKind::NamedAnon(symbol) => { - write!(f, "{:?}.NamedAnon({:?})", self.var, symbol) - } - } - } -} +//#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] +//#[derive(HashStable)] +//pub struct BoundRegion { +// pub var: BoundVar, +// pub kind: BoundRegionKind, +//} +// +//impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundRegion { +// fn var(self) -> BoundVar { +// self.var +// } +// +// fn assert_eq(self, var: ty::BoundVariableKind) { +// assert_eq!(self.kind, var.expect_region()) +// } +// +// fn new(var: BoundVar, kind: BoundRegionKind) -> Self { +// Self { var, kind } +// } +//} + +//impl core::fmt::Debug for BoundRegion { +// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +// match self.kind { +// BoundRegionKind::Anon => write!(f, "{:?}", self.var), +// BoundRegionKind::ClosureEnv => write!(f, "{:?}.Env", self.var), +// BoundRegionKind::Named(def) => { +// write!(f, "{:?}.Named({:?})", self.var, def) +// } +// BoundRegionKind::NamedAnon(symbol) => { +// write!(f, "{:?}.NamedAnon({:?})", self.var, symbol) +// } +// } +// } +//} impl BoundRegionKind { pub fn is_named(&self, tcx: TyCtxt<'_>) -> bool { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index c3834607e9236..6dfb7f32077f7 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -381,23 +381,27 @@ impl ParamConst { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] -#[derive(HashStable)] -pub struct BoundTy { - pub var: BoundVar, - pub kind: BoundTyKind, -} - -impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundTy { - fn var(self) -> BoundVar { - self.var - } - - fn assert_eq(self, var: ty::BoundVariableKind) { - assert_eq!(self.kind, var.expect_ty()) - } -} - +//#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] +//#[derive(HashStable)] +//pub struct BoundTy { +// pub var: BoundVar, +// pub kind: BoundTyKind, +//} +// +//impl<'tcx> rustc_type_ir::inherent::BoundVarLike> for BoundTy { +// fn var(self) -> BoundVar { +// self.var +// } +// +// fn assert_eq(self, var: ty::BoundVariableKind) { +// assert_eq!(self.kind, var.expect_ty()) +// } +// +// fn new(var: BoundVar, kind: BoundRegionKind) -> Self { +// Self { var, kind } +// } +//} +// #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum BoundTyKind { @@ -509,7 +513,10 @@ impl<'tcx> Ty<'tcx> { } #[inline] - pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> { + pub fn new_placeholder( + tcx: TyCtxt<'tcx>, + placeholder: ty::PlaceholderType>, + ) -> Ty<'tcx> { Ty::new(tcx, Placeholder(placeholder)) } @@ -958,7 +965,7 @@ impl<'tcx> rustc_type_ir::inherent::Ty> for Ty<'tcx> { Ty::new_param(tcx, param.index, param.name) } - fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Self { + fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType>) -> Self { Ty::new_placeholder(tcx, placeholder) } diff --git a/compiler/rustc_next_trait_solver/src/placeholder.rs b/compiler/rustc_next_trait_solver/src/placeholder.rs index c8016759f239a..a36ae1b6ff8ce 100644 --- a/compiler/rustc_next_trait_solver/src/placeholder.rs +++ b/compiler/rustc_next_trait_solver/src/placeholder.rs @@ -16,9 +16,9 @@ where // These three maps track the bound variable that were replaced by placeholders. It might be // nice to remove these since we already have the `kind` in the placeholder; we really just need // the `var` (but we *could* bring that into scope if we were to track them as we pass them). - mapped_regions: IndexMap, - mapped_types: IndexMap, - mapped_consts: IndexMap, + mapped_regions: IndexMap, + mapped_types: IndexMap, + mapped_consts: IndexMap, ty::BoundConst>, // The current depth relative to *this* folding, *not* the entire normalization. In other words, // the depth of binders we've passed here. current_index: ty::DebruijnIndex, @@ -40,9 +40,9 @@ where value: T, ) -> ( T, - IndexMap, - IndexMap, - IndexMap, + IndexMap, + IndexMap, + IndexMap, ty::BoundConst>, ) { let mut replacer = BoundVarReplacer { infcx, diff --git a/compiler/rustc_public/src/ty.rs b/compiler/rustc_public/src/ty.rs index 14656a2e594ad..0e3885737c3a2 100644 --- a/compiler/rustc_public/src/ty.rs +++ b/compiler/rustc_public/src/ty.rs @@ -241,11 +241,11 @@ pub struct EarlyParamRegion { pub(crate) type BoundVar = u32; -#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] -pub struct BoundRegion { - pub var: BoundVar, - pub kind: BoundRegionKind, -} +//#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] +//pub struct BoundRegion { +// pub var: BoundVar, +// pub kind: BoundRegionKind, +//} pub(crate) type UniverseIndex = u32; diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 19ccf6a55bf1a..0c0bc42d3c5b8 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -220,9 +220,9 @@ pub fn with_replaced_escaping_bound_vars< /// The inverse of [`BoundVarReplacer`]: replaces placeholders with the bound vars from which they came. pub struct PlaceholderReplacer<'a, 'tcx> { infcx: &'a InferCtxt<'tcx>, - mapped_regions: FxIndexMap, ty::BoundRegion>, + mapped_regions: FxIndexMap>, ty::BoundRegion>, mapped_types: FxIndexMap, ty::BoundTy>, - mapped_consts: FxIndexMap, ty::BoundConst>, + mapped_consts: FxIndexMap>, ty::BoundConst>, universe_indices: &'a [Option], current_index: ty::DebruijnIndex, } @@ -230,9 +230,9 @@ pub struct PlaceholderReplacer<'a, 'tcx> { impl<'a, 'tcx> PlaceholderReplacer<'a, 'tcx> { pub fn replace_placeholders>>( infcx: &'a InferCtxt<'tcx>, - mapped_regions: FxIndexMap, ty::BoundRegion>, + mapped_regions: FxIndexMap>, ty::BoundRegion>, mapped_types: FxIndexMap, ty::BoundTy>, - mapped_consts: FxIndexMap, ty::BoundConst>, + mapped_consts: FxIndexMap>, ty::BoundConst>, universe_indices: &'a [Option], value: T, ) -> T { diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index b5c9080154cea..e03db071006fe 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -1003,3 +1003,157 @@ where }) } } + +#[derive_where(Clone, PartialEq, Ord, Eq, Hash; I: Interner)] +#[derive_where(PartialOrd; I: Interner)] +#[derive_where(Copy; I: Interner)] +#[cfg_attr( + feature = "nightly", + derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) +)] +pub struct BoundRegion { + pub var: ty::BoundVar, + pub kind: I::BoundRegionKind, +} + +impl BoundVarLike for BoundRegion { + fn var(self) -> ty::BoundVar { + self.var + } + + fn assert_eq>(self, var: T) { + assert_eq!(self.kind, var.expect_region()) + } + + fn new(var: ty::BoundVar, kind: I::BoundRegionKind) -> Self { + Self { var, kind } + } +} + +pub type PlaceholderRegion = ty::Placeholder>; + +impl PlaceholderLike for PlaceholderRegion { + type Bound = BoundRegion; + + fn universe(self) -> UniverseIndex { + self.universe + } + + fn var(self) -> ty::BoundVar { + self.bound.var() + } + + fn with_updated_universe(self, ui: UniverseIndex) -> Self { + ty::Placeholder::new(ui, self.bound) + } + + fn new(ui: UniverseIndex, bound: BoundRegion) -> Self { + ty::Placeholder::new(ui, bound) + } + + // This is a Problem. I think that `I::BoundRegionKind` + fn new_anon(ui: UniverseIndex, var: ty::BoundVar, kind: I::BoundRegionKind) -> Self { + ty::Placeholder::new(ui, BoundRegion { var, kind }) + } +} + +#[derive_where(Clone, PartialEq, Ord, Hash; I: Interner)] +#[derive_where(PartialOrd; I: Interner)] +#[derive_where(Copy; I: Interner)] +#[cfg_attr( + feature = "nightly", + derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) +)] +pub struct BoundTy { + pub var: ty::BoundVar, + pub kind: I::BoundTyKind, +} + +impl BoundVarLike for BoundTy { + fn var(self) -> ty::BoundVar { + self.var + } + + fn assert_eq>(self, var: T) { + assert_eq!(self.kind, var.expect_ty()) + } + + fn new(var: ty::BoundVar, kind: I::BoundRegionKind) -> Self { + Self { var, kind } + } +} + +pub type PlaceholderType = ty::Placeholder>; + +impl PlaceholderLike for PlaceholderType { + type Bound = BoundTy; + + fn universe(self) -> UniverseIndex { + self.universe + } + + fn var(self) -> ty::BoundVar { + self.bound.var + } + + fn with_updated_universe(self, ui: UniverseIndex) -> Self { + ty::Placeholder::new(ui, self.bound) + } + + fn new(ui: UniverseIndex, bound: BoundTy) -> Self { + ty::Placeholder::new(ui, bound) + } + + fn new_anon(ui: UniverseIndex, var: ty::BoundVar, kind: I::BoundRegionKind) -> Self { + ty::Placeholder::new(ui, BoundTy { var, kind }) + } +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr( + feature = "nightly", + derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) +)] +pub struct BoundConst { + pub var: ty::BoundVar, +} + +impl BoundVarLike for BoundConst { + fn var(self) -> ty::BoundVar { + self.var + } + + fn assert_eq>(self, var: T) { + var.expect_const() + } + + fn new(var: ty::BoundVar, _kind: I::BoundRegionKind) -> Self { + Self { var } + } +} + +pub type PlaceholderConst = ty::Placeholder; + +impl PlaceholderLike for PlaceholderConst { + type Bound = BoundConst; + + fn universe(self) -> UniverseIndex { + self.universe + } + + fn var(self) -> ty::BoundVar { + self.bound.var + } + + fn with_updated_universe(self, ui: UniverseIndex) -> Self { + ty::Placeholder::new(ui, self.bound) + } + + fn new(ui: UniverseIndex, bound: BoundConst) -> Self { + ty::Placeholder::new(ui, bound) + } + + fn new_anon(ui: UniverseIndex, var: ty::BoundVar, _kind: I::BoundRegionKind) -> Self { + ty::Placeholder::new(ui, BoundConst { var }) + } +} diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 47e753d787311..87af2e806ebf5 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -11,7 +11,7 @@ use rustc_type_ir_macros::{ use crate::data_structures::HashMap; use crate::inherent::*; -use crate::{self as ty, Interner, TypingMode, UniverseIndex}; +use crate::{self as ty, Interner, PlaceholderRegion, TypingMode, UniverseIndex}; #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] @@ -116,13 +116,13 @@ pub enum CanonicalVarKind { /// A "placeholder" that represents "any region". Created when you /// are solving a goal like `for<'a> T: Foo<'a>` to represent the /// bound region `'a`. - PlaceholderRegion(I::PlaceholderRegion), + PlaceholderRegion(PlaceholderRegion), /// Some kind of const inference variable. Const(UniverseIndex), /// A "placeholder" that represents "any const". - PlaceholderConst(I::PlaceholderConst), + PlaceholderConst(ty::PlaceholderConst), } impl Eq for CanonicalVarKind {} diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index f315e8b3e11ce..115f3884529ac 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -26,10 +26,10 @@ pub enum ConstKind { Infer(InferConst), /// Bound const variable, used only when preparing a trait query. - Bound(BoundVarIndexKind, I::BoundConst), + Bound(BoundVarIndexKind, ty::BoundConst), /// A placeholder const - universally quantified higher-ranked const. - Placeholder(I::PlaceholderConst), + Placeholder(ty::PlaceholderConst), /// An unnormalized const item such as an anon const or assoc const or free const item. /// Right now anything other than anon consts does not actually work properly but this diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 75ba0231d98cb..f7ea257e7d541 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -13,7 +13,7 @@ use crate::fold::{TypeFoldable, TypeSuperFoldable}; use crate::relate::Relate; use crate::solve::{AdtDestructorKind, SizedTraitKind}; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt}; -use crate::{self as ty, CollectAndApply, Interner, UpcastFrom}; +use crate::{self as ty, CollectAndApply, Interner, PlaceholderRegion, UpcastFrom}; pub trait Ty>: Copy @@ -44,7 +44,7 @@ pub trait Ty>: fn new_placeholder(interner: I, param: I::PlaceholderTy) -> Self; - fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: I::BoundTy) -> Self; + fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundTy) -> Self; fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self; @@ -236,7 +236,7 @@ pub trait Region>: fn new_static(interner: I) -> Self; - fn new_placeholder(interner: I, var: I::PlaceholderRegion) -> Self; + fn new_placeholder(interner: I, var: PlaceholderRegion) -> Self; fn is_bound(self) -> bool { matches!(self.kind(), ty::ReBound(..)) @@ -260,13 +260,13 @@ pub trait Const>: fn new_var(interner: I, var: ty::ConstVid) -> Self; - fn new_bound(interner: I, debruijn: ty::DebruijnIndex, bound_const: I::BoundConst) -> Self; + fn new_bound(interner: I, debruijn: ty::DebruijnIndex, bound_const: ty::BoundConst) -> Self; fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self; fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self; - fn new_placeholder(interner: I, param: I::PlaceholderConst) -> Self; + fn new_placeholder(interner: I, param: ty::PlaceholderConst) -> Self; fn new_unevaluated(interner: I, uv: ty::UnevaluatedConst) -> Self; @@ -544,14 +544,14 @@ pub trait PlaceholderLike: Copy + Debug + Hash + Eq { type Bound: BoundVarLike; fn new(ui: ty::UniverseIndex, bound: Self::Bound) -> Self; - fn new_anon(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self; - fn with_updated_universe(self, ui: ty::UniverseIndex) -> Self; + fn new_anon(ui: ty::UniverseIndex, var: ty::BoundVar, anon_kind: T) -> Self; + fn with_updated_universe(self, universe: ty::UniverseIndex) -> Self; } -pub trait PlaceholderConst: PlaceholderLike { +pub trait PlaceholderConst: PlaceholderLike { fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty; } -impl PlaceholderConst for I::PlaceholderConst { +impl PlaceholderConst for ty::PlaceholderConst { fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty { let mut candidates = env.caller_bounds().iter().filter_map(|clause| { // `ConstArgHasType` are never desugared to be higher ranked. @@ -596,7 +596,17 @@ pub trait IntoKind { pub trait BoundVarLike: Copy + Debug + Hash + Eq { fn var(self) -> ty::BoundVar; - fn assert_eq(self, var: I::BoundVarKind); + fn assert_eq>(self, var: T); + + fn new(var: ty::BoundVar, kind: I::BoundRegionKind) -> Self; +} + +pub trait BoundVariableKindLike: Copy + Debug + Hash + Eq { + fn expect_region(self) -> I::BoundRegionKind; + + fn expect_ty(self) -> I::BoundTyKind; + + fn expect_const(self); } pub trait ParamLike: Copy + Debug + Hash + Eq { diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 3884f29a4fc80..52580d47d7ee7 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -120,8 +120,9 @@ pub trait Interner: type Tys: Tys; type FnInputTys: Copy + Debug + Hash + Eq + SliceLike + TypeVisitable; type ParamTy: ParamLike; - type BoundTy: BoundVarLike; - type PlaceholderTy: PlaceholderLike; + //type BoundTy: BoundVarLike; + type BoundTyKind: Copy + Hash + PartialEq + Eq + Debug; + type PlaceholderTy: PlaceholderLike>; type Symbol: Copy + Hash + PartialEq + Eq + Debug; // Things stored inside of tys @@ -149,8 +150,8 @@ pub trait Interner: // Kinds of consts type Const: Const; type ParamConst: Copy + Debug + Hash + Eq + ParamLike; - type BoundConst: BoundVarLike; - type PlaceholderConst: PlaceholderConst; + //type BoundConst: BoundVarLike; + //type PlaceholderConst: PlaceholderConst; type ValueConst: ValueConst; type ExprConst: ExprConst; type ValTree: Copy + Debug + Hash + Eq; @@ -160,7 +161,10 @@ pub trait Interner: type EarlyParamRegion: ParamLike; type LateParamRegion: Copy + Debug + Hash + Eq; type BoundRegion: BoundVarLike; - type PlaceholderRegion: PlaceholderLike; + type BoundRegionKind: Copy + Debug + Hash + Eq; + type BoundVariableKind: Copy + Debug + Hash + Eq; + // type BoundVar: BoundVarLike; + // type PlaceholderRegion: PlaceholderLike; type RegionAssumptions: Copy + Debug diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 9acf9ff8557e7..ca4709ff04d7c 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -8,7 +8,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContex use rustc_type_ir_macros::GenericTypeVisitable; use self::RegionKind::*; -use crate::{BoundVarIndexKind, Interner}; +use crate::{BoundVarIndexKind, Interner, PlaceholderRegion}; rustc_index::newtype_index! { /// A **region** **v**ariable **ID**. @@ -170,7 +170,7 @@ pub enum RegionKind { /// Should not exist outside of type inference. /// /// Used when instantiating a `forall` binder via `infcx.enter_forall`. - RePlaceholder(I::PlaceholderRegion), + RePlaceholder(PlaceholderRegion), /// Erased region, used by trait selection, in MIR and during codegen. ReErased, @@ -216,7 +216,6 @@ where I::EarlyParamRegion: HashStable, I::BoundRegion: HashStable, I::LateParamRegion: HashStable, - I::PlaceholderRegion: HashStable, { #[inline] fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 34bb3cd8a6c35..3d5a81b0ffa32 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -233,7 +233,7 @@ pub enum TyKind { /// /// [1]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html /// [2]: https://rustc-dev-guide.rust-lang.org/traits/canonical-queries.html - Bound(BoundVarIndexKind, I::BoundTy), + Bound(BoundVarIndexKind, ty::BoundTy), /// A placeholder type, used during higher ranked subtyping to instantiate /// bound variables.