rustc_index/
lib.rs

1// tidy-alphabetical-start
2#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
3#![cfg_attr(feature = "nightly", feature(extend_one, step_trait, test))]
4#![cfg_attr(feature = "nightly", feature(new_range_api))]
5// tidy-alphabetical-end
6
7pub mod bit_set;
8#[cfg(feature = "nightly")]
9pub mod interval;
10
11mod idx;
12mod slice;
13mod vec;
14
15pub use idx::{Idx, IntoSliceIdx};
16pub use rustc_index_macros::newtype_index;
17pub use slice::IndexSlice;
18#[doc(no_inline)]
19pub use vec::IndexVec;
20
21/// Type size assertion. The first argument is a type and the second argument is its expected size.
22///
23/// <div class="warning">
24///
25/// Emitting hard errors from size assertions like this is generally not
26/// recommended, especially in libraries, because they can cause build failures if the layout
27/// algorithm or dependencies change. Here in rustc we control the toolchain and layout algorithm,
28/// so the former is not a problem. For the latter we have a lockfile as rustc is an application and
29/// precompiled library.
30///
31/// Short version: Don't copy this macro into your own code. Use a `#[test]` instead.
32///
33/// </div>
34#[macro_export]
35#[cfg(not(feature = "rustc_randomized_layouts"))]
36macro_rules! static_assert_size {
37    ($ty:ty, $size:expr) => {
38        const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
39    };
40}
41
42#[macro_export]
43#[cfg(feature = "rustc_randomized_layouts")]
44macro_rules! static_assert_size {
45    ($ty:ty, $size:expr) => {
46        // no effect other than using the statements.
47        // struct sizes are not deterministic under randomized layouts
48        const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>());
49    };
50}
51
52#[macro_export]
53macro_rules! indexvec {
54    ($expr:expr; $n:expr) => {
55        IndexVec::from_raw(vec![$expr; $n])
56    };
57    ($($expr:expr),* $(,)?) => {
58        IndexVec::from_raw(vec![$($expr),*])
59    };
60}