• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result24     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, "{b:#04x}u8"),
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 {
min_align(&self) -> usize34     fn min_align(&self) -> usize;
35 
is_mutable(&self) -> bool36     fn is_mutable(&self) -> bool;
37 }
38 
39 impl Def for ! {}
40 impl Ref for ! {
min_align(&self) -> usize41     fn min_align(&self) -> usize {
42         unreachable!()
43     }
is_mutable(&self) -> bool44     fn is_mutable(&self) -> bool {
45         unreachable!()
46     }
47 }
48 
49 #[cfg(feature = "rustc")]
50 pub mod rustc {
51     use rustc_middle::mir::Mutability;
52     use rustc_middle::ty::{self, Ty};
53 
54     /// A reference in the layout.
55     #[derive(Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Clone, Copy)]
56     pub struct Ref<'tcx> {
57         pub lifetime: ty::Region<'tcx>,
58         pub ty: Ty<'tcx>,
59         pub mutability: Mutability,
60         pub align: usize,
61     }
62 
63     impl<'tcx> super::Ref for Ref<'tcx> {
min_align(&self) -> usize64         fn min_align(&self) -> usize {
65             self.align
66         }
67 
is_mutable(&self) -> bool68         fn is_mutable(&self) -> bool {
69             match self.mutability {
70                 Mutability::Mut => true,
71                 Mutability::Not => false,
72             }
73         }
74     }
75     impl<'tcx> Ref<'tcx> {}
76 
77     /// A visibility node in the layout.
78     #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
79     pub enum Def<'tcx> {
80         Adt(ty::AdtDef<'tcx>),
81         Variant(&'tcx ty::VariantDef),
82         Field(&'tcx ty::FieldDef),
83         Primitive,
84     }
85 
86     impl<'tcx> super::Def for Def<'tcx> {}
87 }
88