Skip to content

Commit e49aa04

Browse files
committed
add RegionDef
1 parent 02b01a4 commit e49aa04

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ impl<'tcx> Tables<'tcx> {
8686
stable_mir::ty::ImplDef(self.create_def_id(did))
8787
}
8888

89+
pub fn region_def(&mut self, did: DefId) -> stable_mir::ty::RegionDef {
90+
stable_mir::ty::RegionDef(self.create_def_id(did))
91+
}
92+
8993
pub fn prov(&mut self, aid: AllocId) -> stable_mir::ty::Prov {
9094
stable_mir::ty::Prov(self.create_alloc_id(aid))
9195
}

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use hir::def::DefKind;
10+
use crate::rustc_internal::{self, opaque};
11+
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
12+
use crate::stable_mir::ty::{
13+
EarlyBoundRegion, FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
14+
};
15+
use crate::stable_mir::{self, CompilerError, Context};
1116
use rustc_hir as hir;
1217
use rustc_middle::mir;
1318
use rustc_middle::mir::interpret::{alloc_range, AllocId};
@@ -1506,6 +1511,27 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
15061511
}
15071512
}
15081513

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

compiler/stable_mir/src/ty.rs

Lines changed: 6 additions & 3 deletions
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

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

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

0 commit comments

Comments
 (0)