rustc_transmute/maybe_transmutable/
query_context.rs

1use crate::layout;
2
3/// Context necessary to answer the question "Are these types transmutable?".
4pub(crate) trait QueryContext {
5    type Def: layout::Def;
6    type Ref: layout::Ref;
7}
8
9#[cfg(test)]
10pub(crate) mod test {
11    use super::QueryContext;
12
13    pub(crate) struct UltraMinimal;
14
15    #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
16    pub(crate) enum Def {
17        HasSafetyInvariants,
18        NoSafetyInvariants,
19    }
20
21    impl crate::layout::Def for Def {
22        fn has_safety_invariants(&self) -> bool {
23            self == &Self::HasSafetyInvariants
24        }
25    }
26
27    impl QueryContext for UltraMinimal {
28        type Def = Def;
29        type Ref = !;
30    }
31}
32
33#[cfg(feature = "rustc")]
34mod rustc {
35    use rustc_middle::ty::TyCtxt;
36
37    use super::*;
38
39    impl<'tcx> super::QueryContext for TyCtxt<'tcx> {
40        type Def = layout::rustc::Def<'tcx>;
41        type Ref = layout::rustc::Ref<'tcx>;
42    }
43}