|
| 1 | +//! Module containing the translation from stable mir constructs to the rustc counterpart. |
| 2 | +//! |
| 3 | +//! This module will only include a few constructs to allow users to invoke internal rustc APIs |
| 4 | +//! due to incomplete stable coverage. |
| 5 | +
|
| 6 | +// Prefer importing stable_mir over internal rustc constructs to make this file more readable. |
| 7 | +use crate::rustc_smir::{MaybeStable, Tables}; |
| 8 | +use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy}; |
| 9 | +use stable_mir::ty::{Const, GenericArgKind, GenericArgs, Region, Ty}; |
| 10 | +use stable_mir::DefId; |
| 11 | + |
| 12 | +use super::RustcInternal; |
| 13 | + |
| 14 | +impl<'tcx> RustcInternal<'tcx> for DefId { |
| 15 | + type T = rustc_span::def_id::DefId; |
| 16 | + fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T { |
| 17 | + tables.def_ids[*self] |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +impl<'tcx> RustcInternal<'tcx> for GenericArgs { |
| 22 | + type T = rustc_ty::GenericArgsRef<'tcx>; |
| 23 | + fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T { |
| 24 | + tables.tcx.mk_args_from_iter(self.0.iter().map(|arg| arg.internal(tables))) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +impl<'tcx> RustcInternal<'tcx> for GenericArgKind { |
| 29 | + type T = rustc_ty::GenericArg<'tcx>; |
| 30 | + fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T { |
| 31 | + match self { |
| 32 | + GenericArgKind::Lifetime(reg) => reg.internal(tables).into(), |
| 33 | + GenericArgKind::Type(ty) => ty.internal(tables).into(), |
| 34 | + GenericArgKind::Const(cnst) => cnst.internal(tables).into(), |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl<'tcx> RustcInternal<'tcx> for Region { |
| 40 | + type T = rustc_ty::Region<'tcx>; |
| 41 | + fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T { |
| 42 | + todo!() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +impl<'tcx> RustcInternal<'tcx> for Ty { |
| 47 | + type T = InternalTy<'tcx>; |
| 48 | + fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T { |
| 49 | + match tables.types[self.0] { |
| 50 | + MaybeStable::Stable(_) => todo!(), |
| 51 | + MaybeStable::Rustc(ty) => ty, |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +impl<'tcx> RustcInternal<'tcx> for Const { |
| 57 | + type T = rustc_ty::Const<'tcx>; |
| 58 | + fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T { |
| 59 | + todo!() |
| 60 | + } |
| 61 | +} |
0 commit comments