rustc_smir/rustc_smir/convert/
mod.rs

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