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