9 #![allow(dead_code, unused_variables)]
14 #[cfg(feature = "rustc")]
15 pub(crate) use rustc_data_structures::fx::{FxHashMap as Map, FxHashSet as Set};
17 #[cfg(not(feature = "rustc"))]
18 pub(crate) use std::collections::{HashMap as Map, HashSet as Set};
20 pub(crate) mod layout;
21 pub(crate) mod maybe_transmutable;
31 /// The type encodes answers to the question: "Are these types transmutable?"
32 #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone)]
37 /// `Src` is transmutable into `Dst`.
40 /// `Src` is NOT transmutable into `Dst`.
43 /// `Src` is transmutable into `Dst`, if `src` is transmutable into `dst`.
44 IfTransmutable { src: R, dst: R },
46 /// `Src` is transmutable into `Dst`, if all of the enclosed requirements are met.
47 IfAll(Vec<Answer<R>>),
49 /// `Src` is transmutable into `Dst` if any of the enclosed requirements are met.
50 IfAny(Vec<Answer<R>>),
53 /// Answers: Why wasn't the source type transmutable into the destination type?
54 #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone)]
56 /// The layout of the source type is unspecified.
58 /// The layout of the destination type is unspecified.
60 /// The layout of the destination type is bit-incompatible with the source type.
62 /// There aren't any public constructors for `Dst`.
64 /// `Dst` is larger than `Src`, and the excess bytes were not exclusively uninitialized.
68 #[cfg(feature = "rustc")]
70 use rustc_infer::infer::InferCtxt;
71 use rustc_macros::{TypeFoldable, TypeVisitable};
72 use rustc_middle::traits::ObligationCause;
73 use rustc_middle::ty::Binder;
74 use rustc_middle::ty::Ty;
76 /// The source and destination types of a transmutation.
77 #[derive(TypeFoldable, TypeVisitable, Debug, Clone, Copy)]
78 pub struct Types<'tcx> {
81 /// The destination type.
85 pub struct TransmuteTypeEnv<'cx, 'tcx> {
86 infcx: &'cx InferCtxt<'cx, 'tcx>,
89 impl<'cx, 'tcx> TransmuteTypeEnv<'cx, 'tcx> {
90 pub fn new(infcx: &'cx InferCtxt<'cx, 'tcx>) -> Self {
95 pub fn is_transmutable(
97 cause: ObligationCause<'tcx>,
98 src_and_dst: Binder<'tcx, Types<'tcx>>,
100 assume: crate::Assume,
101 ) -> crate::Answer<crate::layout::rustc::Ref<'tcx>> {
102 let src = src_and_dst.map_bound(|types| types.src).skip_binder();
103 let dst = src_and_dst.map_bound(|types| types.dst).skip_binder();
104 crate::maybe_transmutable::MaybeTransmutableQuery::new(
116 #[cfg(feature = "rustc")]