Use #[derive] instead of custom syntax in all newtype_index

This commit is contained in:
Nilstrieb 2022-12-18 20:53:08 +01:00
parent 37efc81072
commit b4d739ef12
7 changed files with 14 additions and 26 deletions

View File

@ -1,11 +1,9 @@
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::parse::*;
use syn::punctuated::Punctuated;
use syn::*;
mod kw {
syn::custom_keyword!(derive);
syn::custom_keyword!(DEBUG_FORMAT);
syn::custom_keyword!(MAX);
syn::custom_keyword!(ENCODABLE);
@ -57,16 +55,6 @@ impl Parse for Newtype {
body.parse::<Token![..]>()?;
} else {
loop {
if body.lookahead1().peek(kw::derive) {
body.parse::<kw::derive>()?;
let derives;
bracketed!(derives in body);
let derives: Punctuated<Path, Token![,]> =
derives.parse_terminated(Path::parse)?;
try_comma()?;
derive_paths.extend(derives);
continue;
}
if body.lookahead1().peek(kw::DEBUG_FORMAT) {
body.parse::<kw::DEBUG_FORMAT>()?;
body.parse::<Token![=]>()?;

View File

@ -147,8 +147,8 @@ rustc_index::newtype_index! {
///
/// * The subscope with `first_statement_index == 1` is scope of `c`,
/// and thus does not include EXPR_2, but covers the `...`.
#[derive(HashStable)]
pub struct FirstStatementIndex {
derive [HashStable]
}
}

View File

@ -10,8 +10,8 @@ rustc_index::newtype_index! {
/// CounterValueReference.as_u32() (which ascend from 1) or an ExpressionOperandId.as_u32()
/// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a
/// constant value of `0`.
#[derive(HashStable)]
pub struct ExpressionOperandId {
derive [HashStable]
DEBUG_FORMAT = "ExpressionOperandId({})",
MAX = 0xFFFF_FFFF,
}
@ -32,8 +32,8 @@ impl ExpressionOperandId {
}
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct CounterValueReference {
derive [HashStable]
DEBUG_FORMAT = "CounterValueReference({})",
MAX = 0xFFFF_FFFF,
}
@ -56,8 +56,8 @@ rustc_index::newtype_index! {
/// InjectedExpressionId.as_u32() converts to ExpressionOperandId.as_u32()
///
/// Values descend from u32::MAX.
#[derive(HashStable)]
pub struct InjectedExpressionId {
derive [HashStable]
DEBUG_FORMAT = "InjectedExpressionId({})",
MAX = 0xFFFF_FFFF,
}
@ -67,8 +67,8 @@ rustc_index::newtype_index! {
/// InjectedExpressionIndex.as_u32() translates to u32::MAX - ExpressionOperandId.as_u32()
///
/// Values ascend from 0.
#[derive(HashStable)]
pub struct InjectedExpressionIndex {
derive [HashStable]
DEBUG_FORMAT = "InjectedExpressionIndex({})",
MAX = 0xFFFF_FFFF,
}
@ -78,8 +78,8 @@ rustc_index::newtype_index! {
/// MappedExpressionIndex values ascend from zero, and are recalculated indexes based on their
/// array position in the LLVM coverage map "Expressions" array, which is assembled during the
/// "mapgen" process. They cannot be computed algorithmically, from the other `newtype_index`s.
#[derive(HashStable)]
pub struct MappedExpressionIndex {
derive [HashStable]
DEBUG_FORMAT = "MappedExpressionIndex({})",
MAX = 0xFFFF_FFFF,
}

View File

@ -654,8 +654,8 @@ impl SourceInfo {
// Variables and temps
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct Local {
derive [HashStable]
DEBUG_FORMAT = "_{}",
const RETURN_PLACE = 0,
}
@ -1146,8 +1146,8 @@ rustc_index::newtype_index! {
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
#[derive(HashStable)]
pub struct BasicBlock {
derive [HashStable]
DEBUG_FORMAT = "bb{}",
const START_BLOCK = 0,
}
@ -1530,8 +1530,8 @@ rustc_index::newtype_index! {
/// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
#[derive(HashStable)]
pub struct Field {
derive [HashStable]
DEBUG_FORMAT = "field[{}]"
}
}
@ -1757,8 +1757,8 @@ impl Debug for Place<'_> {
// Scopes
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct SourceScope {
derive [HashStable]
DEBUG_FORMAT = "scope[{}]",
const OUTERMOST_SOURCE_SCOPE = 0,
}
@ -2755,8 +2755,8 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
}
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct Promoted {
derive [HashStable]
DEBUG_FORMAT = "promoted[{}]"
}
}

View File

@ -130,8 +130,8 @@ pub struct UnsafetyCheckResult {
}
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct GeneratorSavedLocal {
derive [HashStable]
DEBUG_FORMAT = "_{}",
}
}

View File

@ -608,8 +608,8 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
}
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct UserTypeAnnotationIndex {
derive [HashStable]
DEBUG_FORMAT = "UserType({})",
const START_INDEX = 0,
}

View File

@ -20,8 +20,8 @@ impl ToJson for Endian {
}
rustc_index::newtype_index! {
#[derive(HashStable_Generic)]
pub struct VariantIdx {
derive [HashStable_Generic]
}
}