1
Fork 0

add stable for RegionKind

This commit is contained in:
ouz-a 2023-09-21 12:12:06 +03:00
parent e49aa04000
commit 5dc2214884
2 changed files with 27 additions and 12 deletions

View file

@ -10,7 +10,8 @@
use crate::rustc_internal::{self, opaque}; use crate::rustc_internal::{self, opaque};
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx}; use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
use crate::stable_mir::ty::{ use crate::stable_mir::ty::{
EarlyBoundRegion, FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy, BoundRegion, EarlyBoundRegion, FloatTy, FreeRegion, GenericParamDef, IntTy, Movability, Region,
RigidTy, Span, TyKind, UintTy,
}; };
use crate::stable_mir::{self, CompilerError, Context}; use crate::stable_mir::{self, CompilerError, Context};
use rustc_hir as hir; use rustc_hir as hir;
@ -1505,9 +1506,8 @@ impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
type T = stable_mir::ty::Region; type T = stable_mir::ty::Region;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
// FIXME: add a real implementation of stable regions Region { kind: self.kind().stable(tables) }
opaque(self)
} }
} }
@ -1515,19 +1515,34 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
type T = stable_mir::ty::RegionKind; type T = stable_mir::ty::RegionKind;
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use crate::stable_mir::ty::RegionKind;
match self { match self {
ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion { ty::ReEarlyBound(early_reg) => RegionKind::ReEarlyBound(EarlyBoundRegion {
def_id: tables.region_def(early_reg.def_id), def_id: tables.region_def(early_reg.def_id),
index: early_reg.index, index: early_reg.index,
name: early_reg.name.to_string(), name: early_reg.name.to_string(),
}), }),
ty::ReLateBound(_, _) => todo!(), ty::ReLateBound(db_index, bound_reg) => RegionKind::ReLateBound(
ty::ReFree(_) => todo!(), db_index.as_u32(),
ty::ReStatic => todo!(), BoundRegion { var: bound_reg.var.as_u32(), kind: bound_reg.kind.stable(tables) },
ty::ReVar(_) => todo!(), ),
ty::RePlaceholder(_) => todo!(), ty::ReFree(free_reg) => RegionKind::ReFree(FreeRegion {
ty::ReErased => todo!(), scope: tables.region_def(free_reg.scope),
ty::ReError(_) => todo!(), bound_region: free_reg.bound_region.stable(tables),
}),
ty::ReStatic => RegionKind::ReStatic,
ty::ReVar(vid_reg) => RegionKind::ReVar(vid_reg.as_u32()),
ty::RePlaceholder(place_holder) => {
RegionKind::RePlaceholder(stable_mir::ty::Placeholder {
universe: place_holder.universe.as_u32(),
bound: BoundRegion {
var: place_holder.bound.var.as_u32(),
kind: place_holder.bound.kind.stable(tables),
},
})
}
ty::ReErased => RegionKind::ReErased,
ty::ReError(_) => RegionKind::ReError(()),
} }
} }
} }

View file

@ -35,7 +35,7 @@ pub struct Const {
type Ident = Opaque; type Ident = Opaque;
pub(crate) struct Region { pub(crate) struct Region {
kind: RegionKind, pub kind: RegionKind,
} }
pub enum RegionKind { pub enum RegionKind {