Skip to content

Commit b4d739e

Browse files
committed
Use #[derive] instead of custom syntax in all newtype_index
1 parent 37efc81 commit b4d739e

File tree

7 files changed

+14
-26
lines changed

7 files changed

+14
-26
lines changed

compiler/rustc_macros/src/newtype.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use proc_macro2::{Span, TokenStream};
22
use quote::quote;
33
use syn::parse::*;
4-
use syn::punctuated::Punctuated;
54
use syn::*;
65

76
mod kw {
8-
syn::custom_keyword!(derive);
97
syn::custom_keyword!(DEBUG_FORMAT);
108
syn::custom_keyword!(MAX);
119
syn::custom_keyword!(ENCODABLE);
@@ -57,16 +55,6 @@ impl Parse for Newtype {
5755
body.parse::<Token![..]>()?;
5856
} else {
5957
loop {
60-
if body.lookahead1().peek(kw::derive) {
61-
body.parse::<kw::derive>()?;
62-
let derives;
63-
bracketed!(derives in body);
64-
let derives: Punctuated<Path, Token![,]> =
65-
derives.parse_terminated(Path::parse)?;
66-
try_comma()?;
67-
derive_paths.extend(derives);
68-
continue;
69-
}
7058
if body.lookahead1().peek(kw::DEBUG_FORMAT) {
7159
body.parse::<kw::DEBUG_FORMAT>()?;
7260
body.parse::<Token![=]>()?;

compiler/rustc_middle/src/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ rustc_index::newtype_index! {
147147
///
148148
/// * The subscope with `first_statement_index == 1` is scope of `c`,
149149
/// and thus does not include EXPR_2, but covers the `...`.
150+
#[derive(HashStable)]
150151
pub struct FirstStatementIndex {
151-
derive [HashStable]
152152
}
153153
}
154154

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ rustc_index::newtype_index! {
1010
/// CounterValueReference.as_u32() (which ascend from 1) or an ExpressionOperandId.as_u32()
1111
/// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a
1212
/// constant value of `0`.
13+
#[derive(HashStable)]
1314
pub struct ExpressionOperandId {
14-
derive [HashStable]
1515
DEBUG_FORMAT = "ExpressionOperandId({})",
1616
MAX = 0xFFFF_FFFF,
1717
}
@@ -32,8 +32,8 @@ impl ExpressionOperandId {
3232
}
3333

3434
rustc_index::newtype_index! {
35+
#[derive(HashStable)]
3536
pub struct CounterValueReference {
36-
derive [HashStable]
3737
DEBUG_FORMAT = "CounterValueReference({})",
3838
MAX = 0xFFFF_FFFF,
3939
}
@@ -56,8 +56,8 @@ rustc_index::newtype_index! {
5656
/// InjectedExpressionId.as_u32() converts to ExpressionOperandId.as_u32()
5757
///
5858
/// Values descend from u32::MAX.
59+
#[derive(HashStable)]
5960
pub struct InjectedExpressionId {
60-
derive [HashStable]
6161
DEBUG_FORMAT = "InjectedExpressionId({})",
6262
MAX = 0xFFFF_FFFF,
6363
}
@@ -67,8 +67,8 @@ rustc_index::newtype_index! {
6767
/// InjectedExpressionIndex.as_u32() translates to u32::MAX - ExpressionOperandId.as_u32()
6868
///
6969
/// Values ascend from 0.
70+
#[derive(HashStable)]
7071
pub struct InjectedExpressionIndex {
71-
derive [HashStable]
7272
DEBUG_FORMAT = "InjectedExpressionIndex({})",
7373
MAX = 0xFFFF_FFFF,
7474
}
@@ -78,8 +78,8 @@ rustc_index::newtype_index! {
7878
/// MappedExpressionIndex values ascend from zero, and are recalculated indexes based on their
7979
/// array position in the LLVM coverage map "Expressions" array, which is assembled during the
8080
/// "mapgen" process. They cannot be computed algorithmically, from the other `newtype_index`s.
81+
#[derive(HashStable)]
8182
pub struct MappedExpressionIndex {
82-
derive [HashStable]
8383
DEBUG_FORMAT = "MappedExpressionIndex({})",
8484
MAX = 0xFFFF_FFFF,
8585
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ impl SourceInfo {
654654
// Variables and temps
655655

656656
rustc_index::newtype_index! {
657+
#[derive(HashStable)]
657658
pub struct Local {
658-
derive [HashStable]
659659
DEBUG_FORMAT = "_{}",
660660
const RETURN_PLACE = 0,
661661
}
@@ -1146,8 +1146,8 @@ rustc_index::newtype_index! {
11461146
/// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis
11471147
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
11481148
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
1149+
#[derive(HashStable)]
11491150
pub struct BasicBlock {
1150-
derive [HashStable]
11511151
DEBUG_FORMAT = "bb{}",
11521152
const START_BLOCK = 0,
11531153
}
@@ -1530,8 +1530,8 @@ rustc_index::newtype_index! {
15301530
/// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype
15311531
/// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg
15321532
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
1533+
#[derive(HashStable)]
15331534
pub struct Field {
1534-
derive [HashStable]
15351535
DEBUG_FORMAT = "field[{}]"
15361536
}
15371537
}
@@ -1757,8 +1757,8 @@ impl Debug for Place<'_> {
17571757
// Scopes
17581758

17591759
rustc_index::newtype_index! {
1760+
#[derive(HashStable)]
17601761
pub struct SourceScope {
1761-
derive [HashStable]
17621762
DEBUG_FORMAT = "scope[{}]",
17631763
const OUTERMOST_SOURCE_SCOPE = 0,
17641764
}
@@ -2755,8 +2755,8 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
27552755
}
27562756

27572757
rustc_index::newtype_index! {
2758+
#[derive(HashStable)]
27582759
pub struct Promoted {
2759-
derive [HashStable]
27602760
DEBUG_FORMAT = "promoted[{}]"
27612761
}
27622762
}

compiler/rustc_middle/src/mir/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ pub struct UnsafetyCheckResult {
130130
}
131131

132132
rustc_index::newtype_index! {
133+
#[derive(HashStable)]
133134
pub struct GeneratorSavedLocal {
134-
derive [HashStable]
135135
DEBUG_FORMAT = "_{}",
136136
}
137137
}

compiler/rustc_middle/src/ty/typeck_results.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
608608
}
609609

610610
rustc_index::newtype_index! {
611+
#[derive(HashStable)]
611612
pub struct UserTypeAnnotationIndex {
612-
derive [HashStable]
613613
DEBUG_FORMAT = "UserType({})",
614614
const START_INDEX = 0,
615615
}

compiler/rustc_target/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ impl ToJson for Endian {
2020
}
2121

2222
rustc_index::newtype_index! {
23+
#[derive(HashStable_Generic)]
2324
pub struct VariantIdx {
24-
derive [HashStable_Generic]
2525
}
2626
}
2727

0 commit comments

Comments
 (0)