rustc_smir/rustc_smir/convert/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Conversion of internal Rust compiler items to stable ones.

use rustc_abi::FieldIdx;

use crate::rustc_smir::{Stable, Tables};

mod abi;
mod error;
mod mir;
mod ty;

pub(crate) use ty::mir_const_from_ty_const;

impl<'tcx> Stable<'tcx> for rustc_hir::Safety {
    type T = stable_mir::mir::Safety;
    fn stable(&self, _: &mut Tables<'_>) -> Self::T {
        match self {
            rustc_hir::Safety::Unsafe => stable_mir::mir::Safety::Unsafe,
            rustc_hir::Safety::Safe => stable_mir::mir::Safety::Safe,
        }
    }
}

impl<'tcx> Stable<'tcx> for FieldIdx {
    type T = usize;
    fn stable(&self, _: &mut Tables<'_>) -> Self::T {
        self.as_usize()
    }
}

impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineSource {
    type T = stable_mir::mir::CoroutineSource;
    fn stable(&self, _: &mut Tables<'_>) -> Self::T {
        use rustc_hir::CoroutineSource;
        match self {
            CoroutineSource::Block => stable_mir::mir::CoroutineSource::Block,
            CoroutineSource::Closure => stable_mir::mir::CoroutineSource::Closure,
            CoroutineSource::Fn => stable_mir::mir::CoroutineSource::Fn,
        }
    }
}

impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
    type T = stable_mir::mir::CoroutineKind;
    fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
        use rustc_hir::{CoroutineDesugaring, CoroutineKind};
        match *self {
            CoroutineKind::Desugared(CoroutineDesugaring::Async, source) => {
                stable_mir::mir::CoroutineKind::Desugared(
                    stable_mir::mir::CoroutineDesugaring::Async,
                    source.stable(tables),
                )
            }
            CoroutineKind::Desugared(CoroutineDesugaring::Gen, source) => {
                stable_mir::mir::CoroutineKind::Desugared(
                    stable_mir::mir::CoroutineDesugaring::Gen,
                    source.stable(tables),
                )
            }
            CoroutineKind::Coroutine(movability) => {
                stable_mir::mir::CoroutineKind::Coroutine(movability.stable(tables))
            }
            CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, source) => {
                stable_mir::mir::CoroutineKind::Desugared(
                    stable_mir::mir::CoroutineDesugaring::AsyncGen,
                    source.stable(tables),
                )
            }
        }
    }
}

impl<'tcx> Stable<'tcx> for rustc_span::Symbol {
    type T = stable_mir::Symbol;

    fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
        self.to_string()
    }
}

impl<'tcx> Stable<'tcx> for rustc_span::Span {
    type T = stable_mir::ty::Span;

    fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
        tables.create_span(*self)
    }
}