Skip to content

Commit a80c8e5

Browse files
committed
Move LateParamRegion to rustc_type_ir
1 parent 41fb9d4 commit a80c8e5

7 files changed

Lines changed: 59 additions & 30 deletions

File tree

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
121121
type ScalarInt = ty::ScalarInt;
122122
type InternedRegionKind = Interned<'tcx, ty::RegionKind<'tcx>>;
123123
type EarlyParamRegion = ty::EarlyParamRegion;
124-
type LateParamRegion = ty::LateParamRegion;
124+
type LateParamRegionKind = ty::LateParamRegionKind;
125125

126126
type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesClause<'tcx>>;
127127

compiler/rustc_middle/src/ty/region.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use rustc_hir::def_id::DefId;
33
use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension};
44
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Symbol, kw, sym};
55
pub use rustc_type_ir::RegionVid;
6-
use rustc_type_ir::{Region as IrRegion, RegionKind as IrRegionKind};
6+
use rustc_type_ir::{
7+
LateParamRegion as IrLateParamRegion, Region as IrRegion, RegionKind as IrRegionKind,
8+
};
79

810
use crate::ty::{self, BoundVar, TyCtxt};
911

1012
pub type Region<'tcx> = IrRegion<TyCtxt<'tcx>>;
1113
pub type RegionKind<'tcx> = IrRegionKind<TyCtxt<'tcx>>;
14+
pub type LateParamRegion<'tcx> = IrLateParamRegion<TyCtxt<'tcx>>;
1215

1316
#[extension(pub trait RegionExt<'tcx>)]
1417
impl<'tcx> Region<'tcx> {
@@ -170,21 +173,6 @@ impl std::fmt::Debug for EarlyParamRegion {
170173
}
171174
}
172175

173-
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Copy)]
174-
#[derive(StableHash)]
175-
/// The parameter representation of late-bound function parameters, "some region
176-
/// at least as big as the scope `fr.scope`".
177-
///
178-
/// Similar to a placeholder region as we create `LateParam` regions when entering a binder
179-
/// except they are always in the root universe and instead of using a boundvar to distinguish
180-
/// between others we use the `DefId` of the parameter. For this reason the `bound_region` field
181-
/// should basically always be `BoundRegionKind::Named` as otherwise there is no way of telling
182-
/// different parameters apart.
183-
pub struct LateParamRegion {
184-
pub scope: DefId,
185-
pub kind: LateParamRegionKind,
186-
}
187-
188176
/// When liberating bound regions, we map their [`ty::BoundRegionKind`]
189177
/// to this as we need to track the index of anonymous regions. We
190178
/// otherwise end up liberating multiple bound regions to the same

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ impl<'tcx> fmt::Debug for ty::adjustment::PatAdjustment<'tcx> {
6464
}
6565
}
6666

67-
impl fmt::Debug for ty::LateParamRegion {
68-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69-
write!(f, "ReLateParam({:?}, {:?})", self.scope, self.kind)
70-
}
71-
}
72-
7367
impl fmt::Debug for ty::LateParamRegionKind {
7468
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7569
match *self {
@@ -265,7 +259,6 @@ TrivialTypeTraversalAndLiftImpls! {
265259
TrivialLiftImpls! {
266260
rustc_span::ErrorGuaranteed,
267261
ty::EarlyParamRegion,
268-
ty::LateParamRegion,
269262
}
270263

271264
///////////////////////////////////////////////////////////////////////////

compiler/rustc_type_ir/src/interner.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::ops::Deref;
55

66
use rustc_ast_ir::Movability;
77
use rustc_ast_ir::visit::VisitorResult;
8+
use rustc_data_structures::stable_hash::StableHash;
89
use rustc_index::bit_set::DenseBitSet;
910

1011
use crate::fold::TypeFoldable;
@@ -184,8 +185,16 @@ pub trait Interner:
184185
type ScalarInt: Copy + Debug + Hash + Eq;
185186

186187
// Kinds of regions
188+
/// (2026/08/13)
189+
/// Do not uplift, the underlying types differ between r-a and rustc.
190+
///
191+
/// See <https://github.com/rust-lang/rust/pull/160986#issuecomment-5269817932>.
187192
type EarlyParamRegion: ParamLike;
188-
type LateParamRegion: Copy + Debug + Hash + Eq;
193+
/// (2026/08/13)
194+
/// Do not uplift, the underlying types differ between r-a and rustc.
195+
///
196+
/// See <https://github.com/rust-lang/rust/pull/160986#issuecomment-5269817932>.
197+
type LateParamRegionKind: Clone + Copy + Debug + PartialEq + Eq + Hash + StableHash;
189198

190199
type InternedRegionKind: Interned<Self, Value = RegionKind<Self>>;
191200

@@ -522,7 +531,6 @@ declare_lift_into! {
522531
InherentAssocConstId,
523532
InherentAssocTyId,
524533
InternedRegionKind,
525-
LateParamRegion,
526534
OpaqueTyId,
527535
ParamEnv,
528536
PatList,

compiler/rustc_type_ir/src/macros.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,20 @@ TrivialTypeTraversalImpls! {
6262
rustc_ast_ir::Mutability,
6363
// tidy-alphabetical-end
6464
}
65+
66+
macro_rules! TrivialLiftImpls {
67+
($($ty:ty),+ $(,)?) => {
68+
$(
69+
impl<I: $crate::Interner> $crate::lift::Lift<I> for $ty {
70+
type Lifted = Self;
71+
fn lift_to_interner(self, _: I) -> Self {
72+
self
73+
}
74+
}
75+
)+
76+
};
77+
}
78+
79+
TrivialLiftImpls! {
80+
crate::LateParamRegion<I>
81+
}

compiler/rustc_type_ir/src/region_kind.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
88
use rustc_type_ir_macros::GenericTypeVisitable;
99

1010
use self::RegionKind::*;
11-
use crate::{BoundRegion, BoundVarIndexKind, Interner, PlaceholderRegion};
11+
use crate::{BoundRegion, BoundVarIndexKind, Interner, LateParamRegion, PlaceholderRegion};
1212

1313
rustc_index::newtype_index! {
1414
/// A **region** **v**ariable **ID**.
@@ -164,7 +164,7 @@ pub enum RegionKind<I: Interner> {
164164
///
165165
/// See <https://rustc-dev-guide.rust-lang.org/early_late_parameters.html> for
166166
/// more info about early and late bound lifetime parameters.
167-
ReLateParam(I::LateParamRegion),
167+
ReLateParam(LateParamRegion<I>),
168168

169169
/// Static data that has an "infinite" lifetime. Bottom in the region lattice.
170170
ReStatic,
@@ -221,7 +221,6 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
221221
impl<I: Interner> StableHash for RegionKind<I>
222222
where
223223
I::EarlyParamRegion: StableHash,
224-
I::LateParamRegion: StableHash,
225224
I::DefId: StableHash,
226225
I::Symbol: StableHash,
227226
{

compiler/rustc_type_ir/src/sty/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use derive_where::derive_where;
44
#[cfg(feature = "nightly")]
5-
use rustc_macros::StableHash_NoContext;
5+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash_NoContext};
66
use rustc_type_ir_macros::{GenericTypeVisitable, Lift_Generic};
77
use tracing::debug;
88

@@ -213,3 +213,27 @@ impl<I: Interner> TypeFoldable<I> for Region<I> {
213213
folder.fold_region(self)
214214
}
215215
}
216+
217+
#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)]
218+
#[cfg_attr(
219+
feature = "nightly",
220+
derive(Encodable_NoContext, Decodable_NoContext, StableHash_NoContext)
221+
)]
222+
/// The parameter representation of late-bound function parameters, "some region
223+
/// at least as big as the scope `fr.scope`".
224+
///
225+
/// Similar to a placeholder region as we create `LateParam` regions when entering a binder
226+
/// except they are always in the root universe and instead of using a boundvar to distinguish
227+
/// between others we use the `DefId` of the parameter. For this reason the `bound_region` field
228+
/// should basically always be `BoundRegionKind::Named` as otherwise there is no way of telling
229+
/// different parameters apart.
230+
pub struct LateParamRegion<I: Interner> {
231+
pub scope: I::DefId,
232+
pub kind: I::LateParamRegionKind,
233+
}
234+
235+
impl<I: Interner> fmt::Debug for LateParamRegion<I> {
236+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
237+
write!(f, "ReLateParam({:?}, {:?})", self.scope, self.kind)
238+
}
239+
}

0 commit comments

Comments
 (0)