Skip to content

Commit 1e2bde6

Browse files
committed
add stable for RegionKind
1 parent e534b64 commit 1e2bde6

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+26-11
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;
@@ -1508,29 +1509,43 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
15081509
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
15091510
type T = stable_mir::ty::Region;
15101511

1511-
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
1512-
// FIXME: add a real implementation of stable regions
1513-
opaque(self)
1512+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1513+
Region { kind: self.kind().stable(tables) }
15141514
}
15151515
}
15161516

15171517
impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
15181518
type T = stable_mir::ty::RegionKind;
15191519

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

compiler/rustc_smir/src/stable_mir/ty.rs

+1-1
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)