Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
// tidy-alphabetical-start
|
2023-10-24 00:16:14 +00:00
|
|
|
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 03:49:36 +00:00
|
|
|
#![cfg_attr(feature = "nightly", feature(allow_internal_unstable))]
|
|
|
|
// tidy-alphabetical-end
|
2023-10-24 00:16:14 +00:00
|
|
|
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
|
|
|
mod newtype;
|
|
|
|
|
|
|
|
/// Creates a struct type `S` that can be used as an index with
|
|
|
|
/// `IndexVec` and so on.
|
|
|
|
///
|
|
|
|
/// There are two ways of interacting with these indices:
|
|
|
|
///
|
|
|
|
/// - The `From` impls are the preferred way. So you can do
|
|
|
|
/// `S::from(v)` with a `usize` or `u32`. And you can convert back
|
|
|
|
/// to an integer with `u32::from(s)`.
|
|
|
|
///
|
|
|
|
/// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
|
|
|
|
/// to create/return a value.
|
|
|
|
///
|
|
|
|
/// Internally, the index uses a u32, so the index must not exceed
|
2023-11-21 07:42:34 +00:00
|
|
|
/// `u32::MAX`.
|
|
|
|
///
|
|
|
|
/// The impls provided by default are Clone, Copy, PartialEq, Eq, and Hash.
|
|
|
|
///
|
|
|
|
/// Accepted attributes for customization:
|
2023-11-26 22:37:01 +00:00
|
|
|
/// - `#[derive(HashStable_Generic)]`/`#[derive(HashStable)]`: derives
|
2023-11-21 07:42:34 +00:00
|
|
|
/// `HashStable`, as normal.
|
2023-11-26 22:37:01 +00:00
|
|
|
/// - `#[encodable]`: derives `Encodable`/`Decodable`.
|
|
|
|
/// - `#[orderable]`: derives `PartialOrd`/`Ord`, plus step-related methods.
|
|
|
|
/// - `#[debug_format = "Foo({})"]`: derives `Debug` with particular output.
|
|
|
|
/// - `#[max = 0xFFFF_FFFD]`: specifies the max value, which allows niche
|
2023-11-21 07:42:34 +00:00
|
|
|
/// optimizations. The default max value is 0xFFFF_FF00.
|
2023-11-26 22:37:01 +00:00
|
|
|
/// - `#[gate_rustc_only]`: makes parts of the generated code nightly-only.
|
2023-10-24 00:16:14 +00:00
|
|
|
#[proc_macro]
|
2023-12-31 18:35:49 +00:00
|
|
|
#[cfg_attr(feature = "nightly", allow_internal_unstable(step_trait, rustc_attrs, trusted_step))]
|
2023-10-24 00:16:14 +00:00
|
|
|
pub fn newtype_index(input: TokenStream) -> TokenStream {
|
|
|
|
newtype::newtype(input)
|
|
|
|
}
|