rustc_smir/rustc_smir/convert/
mod.rs1use rustc_abi::FieldIdx;
4
5use crate::rustc_smir::{Stable, Tables};
6use crate::stable_mir;
7
8mod abi;
9mod error;
10mod mir;
11mod ty;
12
13impl<'tcx> Stable<'tcx> for rustc_hir::Safety {
14 type T = stable_mir::mir::Safety;
15 fn stable(&self, _: &mut Tables<'_>) -> Self::T {
16 match self {
17 rustc_hir::Safety::Unsafe => stable_mir::mir::Safety::Unsafe,
18 rustc_hir::Safety::Safe => stable_mir::mir::Safety::Safe,
19 }
20 }
21}
22
23impl<'tcx> Stable<'tcx> for FieldIdx {
24 type T = usize;
25 fn stable(&self, _: &mut Tables<'_>) -> Self::T {
26 self.as_usize()
27 }
28}
29
30impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineSource {
31 type T = stable_mir::mir::CoroutineSource;
32 fn stable(&self, _: &mut Tables<'_>) -> Self::T {
33 use rustc_hir::CoroutineSource;
34 match self {
35 CoroutineSource::Block => stable_mir::mir::CoroutineSource::Block,
36 CoroutineSource::Closure => stable_mir::mir::CoroutineSource::Closure,
37 CoroutineSource::Fn => stable_mir::mir::CoroutineSource::Fn,
38 }
39 }
40}
41
42impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
43 type T = stable_mir::mir::CoroutineKind;
44 fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
45 use rustc_hir::{CoroutineDesugaring, CoroutineKind};
46 match *self {
47 CoroutineKind::Desugared(CoroutineDesugaring::Async, source) => {
48 stable_mir::mir::CoroutineKind::Desugared(
49 stable_mir::mir::CoroutineDesugaring::Async,
50 source.stable(tables),
51 )
52 }
53 CoroutineKind::Desugared(CoroutineDesugaring::Gen, source) => {
54 stable_mir::mir::CoroutineKind::Desugared(
55 stable_mir::mir::CoroutineDesugaring::Gen,
56 source.stable(tables),
57 )
58 }
59 CoroutineKind::Coroutine(movability) => {
60 stable_mir::mir::CoroutineKind::Coroutine(movability.stable(tables))
61 }
62 CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, source) => {
63 stable_mir::mir::CoroutineKind::Desugared(
64 stable_mir::mir::CoroutineDesugaring::AsyncGen,
65 source.stable(tables),
66 )
67 }
68 }
69 }
70}
71
72impl<'tcx> Stable<'tcx> for rustc_span::Symbol {
73 type T = stable_mir::Symbol;
74
75 fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
76 self.to_string()
77 }
78}
79
80impl<'tcx> Stable<'tcx> for rustc_span::Span {
81 type T = stable_mir::ty::Span;
82
83 fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
84 tables.create_span(*self)
85 }
86}