Skip to content

Commit e534b64

Browse files
committed
add RegionDef
1 parent 4498098 commit e534b64

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ impl<'tcx> Tables<'tcx> {
135135
stable_mir::ty::ImplDef(self.create_def_id(did))
136136
}
137137

138+
pub fn region_def(&mut self, did: DefId) -> stable_mir::ty::RegionDef {
139+
stable_mir::ty::RegionDef(self.create_def_id(did))
140+
}
141+
138142
pub fn prov(&mut self, aid: AllocId) -> stable_mir::ty::Prov {
139143
stable_mir::ty::Prov(self.create_alloc_id(aid))
140144
}

compiler/rustc_smir/src/rustc_smir/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::rustc_internal::{self, opaque};
1111
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
1212
use crate::stable_mir::ty::{
13-
FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
13+
EarlyBoundRegion, FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
1414
};
1515
use crate::stable_mir::{self, CompilerError, Context};
1616
use rustc_hir as hir;
@@ -1514,6 +1514,27 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
15141514
}
15151515
}
15161516

1517+
impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
1518+
type T = stable_mir::ty::RegionKind;
1519+
1520+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1521+
match self {
1522+
ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion {
1523+
def_id: tables.region_def(early_reg.def_id),
1524+
index: early_reg.index,
1525+
name: early_reg.name.to_string(),
1526+
}),
1527+
ty::ReLateBound(_, _) => todo!(),
1528+
ty::ReFree(_) => todo!(),
1529+
ty::ReStatic => todo!(),
1530+
ty::ReVar(_) => todo!(),
1531+
ty::RePlaceholder(_) => todo!(),
1532+
ty::ReErased => todo!(),
1533+
ty::ReError(_) => todo!(),
1534+
}
1535+
}
1536+
}
1537+
15171538
impl<'tcx> Stable<'tcx> for rustc_span::Span {
15181539
type T = stable_mir::ty::Span;
15191540

compiler/rustc_smir/src/stable_mir/ty.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) struct Region {
3838
kind: RegionKind,
3939
}
4040

41-
enum RegionKind {
41+
pub enum RegionKind {
4242
ReEarlyBound(EarlyBoundRegion),
4343
ReLateBound(DebruijnIndex, BoundRegion),
4444
ReFree(FreeRegion),
@@ -52,7 +52,7 @@ enum RegionKind {
5252
pub(crate) type DebruijnIndex = u32;
5353

5454
pub struct EarlyBoundRegion {
55-
pub def_id: DefId,
55+
pub def_id: RegionDef,
5656
pub index: u32,
5757
pub name: Symbol,
5858
}
@@ -65,7 +65,7 @@ pub struct BoundRegion {
6565
}
6666

6767
pub struct FreeRegion {
68-
pub scope: DefId,
68+
pub scope: RegionDef,
6969
pub bound_region: BoundRegionKind,
7070
}
7171

@@ -196,6 +196,9 @@ pub struct ConstDef(pub(crate) DefId);
196196
#[derive(Clone, PartialEq, Eq, Debug)]
197197
pub struct ImplDef(pub(crate) DefId);
198198

199+
#[derive(Clone, PartialEq, Eq, Debug)]
200+
pub struct RegionDef(pub(crate) DefId);
201+
199202
#[derive(Clone, Debug)]
200203
pub struct GenericArgs(pub Vec<GenericArgKind>);
201204

0 commit comments

Comments
 (0)