]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_transmute/src/layout/mod.rs
Rollup merge of #104003 - c410-f3r:moar-errors, r=petrochenkov
[rust.git] / compiler / rustc_transmute / src / layout / mod.rs
1 use std::fmt::{self, Debug};
2 use std::hash::Hash;
3
4 pub(crate) mod tree;
5 pub(crate) use tree::Tree;
6
7 pub(crate) mod nfa;
8 pub(crate) use nfa::Nfa;
9
10 pub(crate) mod dfa;
11 pub(crate) use dfa::Dfa;
12
13 #[derive(Debug)]
14 pub(crate) struct Uninhabited;
15
16 /// An instance of a byte is either initialized to a particular value, or uninitialized.
17 #[derive(Hash, Eq, PartialEq, Clone, Copy)]
18 pub(crate) enum Byte {
19     Uninit,
20     Init(u8),
21 }
22
23 impl fmt::Debug for Byte {
24     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25         match &self {
26             Self::Uninit => f.write_str("??u8"),
27             Self::Init(b) => write!(f, "{:#04x}u8", b),
28         }
29     }
30 }
31
32 pub(crate) trait Def: Debug + Hash + Eq + PartialEq + Copy + Clone {}
33 pub trait Ref: Debug + Hash + Eq + PartialEq + Copy + Clone {}
34
35 impl Def for ! {}
36 impl Ref for ! {}
37
38 #[cfg(feature = "rustc")]
39 pub(crate) mod rustc {
40     use rustc_middle::mir::Mutability;
41     use rustc_middle::ty;
42     use rustc_middle::ty::Region;
43     use rustc_middle::ty::Ty;
44
45     /// A reference in the layout.
46     #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone, Copy)]
47     pub struct Ref<'tcx> {
48         lifetime: Region<'tcx>,
49         ty: Ty<'tcx>,
50         mutability: Mutability,
51     }
52
53     impl<'tcx> super::Ref for Ref<'tcx> {}
54
55     impl<'tcx> Ref<'tcx> {
56         pub fn min_align(&self) -> usize {
57             todo!()
58         }
59     }
60
61     /// A visibility node in the layout.
62     #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
63     pub enum Def<'tcx> {
64         Adt(ty::AdtDef<'tcx>),
65         Variant(&'tcx ty::VariantDef),
66         Field(&'tcx ty::FieldDef),
67         Primitive,
68     }
69
70     impl<'tcx> super::Def for Def<'tcx> {}
71 }