Skip to content

Commit 5dc2214

Browse files
committed
add stable for RegionKind
1 parent e49aa04 commit 5dc2214

File tree

2 files changed

+27
-12
lines changed
  • compiler

2 files changed

+27
-12
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
use crate::rustc_internal::{self, opaque};
1111
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
1212
use crate::stable_mir::ty::{
13-
EarlyBoundRegion, FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
13+
BoundRegion, EarlyBoundRegion, FloatTy, FreeRegion, GenericParamDef, IntTy, Movability, Region,
14+
RigidTy, Span, TyKind, UintTy,
1415
};
1516
use crate::stable_mir::{self, CompilerError, Context};
1617
use rustc_hir as hir;
@@ -1505,29 +1506,43 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
15051506
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
15061507
type T = stable_mir::ty::Region;
15071508

1508-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
1509-
// FIXME: add a real implementation of stable regions
1510-
opaque(self)
1509+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1510+
Region { kind: self.kind().stable(tables) }
15111511
}
15121512
}
15131513

15141514
impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
15151515
type T = stable_mir::ty::RegionKind;
15161516

15171517
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1518+
use crate::stable_mir::ty::RegionKind;
15181519
match self {
15191520
ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion {
15201521
def_id: tables.region_def(early_reg.def_id),
15211522
index: early_reg.index,
15221523
name: early_reg.name.to_string(),
15231524
}),
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!(),
1525+
ty::ReLateBound(db_index, bound_reg) => RegionKind::ReLateBound(
1526+
db_index.as_u32(),
1527+
BoundRegion { var: bound_reg.var.as_u32(), kind: bound_reg.kind.stable(tables) },
1528+
),
1529+
ty::ReFree(free_reg) => RegionKind::ReFree(FreeRegion {
1530+
scope: tables.region_def(free_reg.scope),
1531+
bound_region: free_reg.bound_region.stable(tables),
1532+
}),
1533+
ty::ReStatic => RegionKind::ReStatic,
1534+
ty::ReVar(vid_reg) => RegionKind::ReVar(vid_reg.as_u32()),
1535+
ty::RePlaceholder(place_holder) => {
1536+
RegionKind::RePlaceholder(stable_mir::ty::Placeholder {
1537+
universe: place_holder.universe.as_u32(),
1538+
bound: BoundRegion {
1539+
var: place_holder.bound.var.as_u32(),
1540+
kind: place_holder.bound.kind.stable(tables),
1541+
},
1542+
})
1543+
}
1544+
ty::ReErased => RegionKind::ReErased,
1545+
ty::ReError(_) => RegionKind::ReError(()),
15311546
}
15321547
}
15331548
}

compiler/stable_mir/src/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Const {
3535

3636
type Ident = Opaque;
3737
pub(crate) struct Region {
38-
kind: RegionKind,
38+
pub kind: RegionKind,
3939
}
4040

4141
pub enum RegionKind {

0 commit comments

Comments
 (0)