rustc_index/
lib.rs

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