2021-07-03 12:18:13 -04:00
|
|
|
use crate::layout;
|
|
|
|
|
|
|
|
|
|
/// Context necessary to answer the question "Are these types transmutable?".
|
|
|
|
|
pub(crate) trait QueryContext {
|
|
|
|
|
type Def: layout::Def;
|
|
|
|
|
type Ref: layout::Ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub(crate) mod test {
|
|
|
|
|
use super::QueryContext;
|
|
|
|
|
|
|
|
|
|
pub(crate) struct UltraMinimal;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
|
|
|
|
|
pub(crate) enum Def {
|
2024-02-26 16:49:25 +00:00
|
|
|
HasSafetyInvariants,
|
|
|
|
|
NoSafetyInvariants,
|
2021-07-03 12:18:13 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-26 16:49:25 +00:00
|
|
|
impl crate::layout::Def for Def {
|
|
|
|
|
fn has_safety_invariants(&self) -> bool {
|
|
|
|
|
self == &Self::HasSafetyInvariants
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-03 12:18:13 -04:00
|
|
|
|
|
|
|
|
impl QueryContext for UltraMinimal {
|
|
|
|
|
type Def = Def;
|
|
|
|
|
type Ref = !;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "rustc")]
|
|
|
|
|
mod rustc {
|
2024-08-08 08:17:55 +08:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2021-07-03 12:18:13 -04:00
|
|
|
|
|
|
|
|
use super::*;
|
2024-07-29 08:13:50 +10:00
|
|
|
|
2021-07-03 12:18:13 -04:00
|
|
|
impl<'tcx> super::QueryContext for TyCtxt<'tcx> {
|
|
|
|
|
type Def = layout::rustc::Def<'tcx>;
|
|
|
|
|
type Ref = layout::rustc::Ref<'tcx>;
|
|
|
|
|
}
|
|
|
|
|
}
|