Skip to main content

rustc_index/
lib.rs

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