diagnostics_tools/diag/
layout.rs

1
2#[ cfg( feature = "diagnostics_compiletime_assertions" ) ]
3mod private
4{
5
6  ///
7  /// Compile-time assertion that two types have the same size.
8  ///
9
10
11  #[ macro_export ]
12  macro_rules! cta_type_same_size
13  {
14    ( $Type1:ty, $Type2:ty $(,)? ) =>
15    {{
16      const _ : fn() = ||
17      {
18        let _ : [ () ; core::mem::size_of::< $Type1 >() ] = [ () ; core::mem::size_of::< $Type2 >() ];
19      };
20      // let _ = core::mem::transmute::< $Type1, $Type2 >;
21      true
22    }}
23  }
24
25  ///
26  /// Compile-time assertion of having the same align.
27  ///
28
29
30  #[ macro_export ]
31  macro_rules! cta_type_same_align
32  {
33    ( $Type1:ty, $Type2:ty $(,)? ) =>
34    {{
35      const _ : fn() = ||
36      {
37        let _ : [ () ; core::mem::align_of::< $Type1 >() ] = [ () ; core::mem::align_of::< $Type2 >() ];
38      };
39      true
40    }};
41  }
42
43  ///
44  /// Compile-time assertion that memory behind two references have the same size.
45  ///
46
47
48  #[ macro_export ]
49  macro_rules! cta_ptr_same_size
50  {
51    ( $Ins1:expr, $Ins2:expr $(,)? ) =>
52    {{
53      #[ allow( unsafe_code, unknown_lints, forget_copy, useless_transmute ) ]
54      let _ = || unsafe
55      {
56        let mut ins1 = core::ptr::read( $Ins1 );
57        core::ptr::write( &mut ins1, core::mem::transmute( core::ptr::read( $Ins2 ) ) );
58        core::mem::forget( ins1 );
59      };
60      true
61    }}
62  }
63
64  ///
65  /// Compile-time assertion that two values have the same size.
66  ///
67  /// Does not consume values.
68  ///
69
70
71  #[ macro_export ]
72  macro_rules! cta_mem_same_size
73  {
74    ( $Ins1:expr, $Ins2:expr $(,)? ) =>
75    {{
76      $crate::cta_ptr_same_size!( &$Ins1, &$Ins2 )
77    }}
78  }
79
80  pub use cta_type_same_size;
81  pub use cta_type_same_align;
82
83  pub use cta_ptr_same_size;
84  pub use cta_mem_same_size;
85}
86
87/// Own namespace of the module.
88#[ allow( unused_imports ) ]
89pub mod own
90{
91  use super::*;
92  #[ doc( inline ) ]
93  pub use orphan::*;
94}
95
96#[ doc( inline ) ]
97#[ allow( unused_imports ) ]
98pub use own::*;
99
100/// Orphan namespace of the module.
101#[ allow( unused_imports ) ]
102pub mod orphan
103{
104  use super::*;
105  #[ doc( inline ) ]
106  pub use exposed::*;
107}
108
109/// Exposed namespace of the module.
110#[ allow( unused_imports ) ]
111pub mod exposed
112{
113  use super::*;
114  #[ doc( inline ) ]
115  pub use prelude::*;
116}
117
118/// Prelude to use essentials: `use my_module::prelude::*`.
119#[ allow( unused_imports ) ]
120pub mod prelude
121{
122  use super::*;
123  #[ cfg( feature = "diagnostics_compiletime_assertions" ) ]
124  #[ doc( inline ) ]
125  pub use private::
126  {
127    cta_type_same_size,
128    cta_type_same_align,
129    cta_ptr_same_size,
130    cta_mem_same_size,
131  };
132}