Skip to content

Commit c9429b1

Browse files
committed
Define index types within thir_with_elements.
The macro already generates other stuff, might as well generate these index types as well.
1 parent a1bea15 commit c9429b1

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,17 @@ use std::ops::Index;
3333

3434
pub mod visit;
3535

36-
newtype_index! {
37-
/// An index to an [`Arm`] stored in [`Thir::arms`]
38-
#[derive(HashStable)]
39-
pub struct ArmId {
40-
DEBUG_FORMAT = "a{}"
41-
}
42-
}
43-
44-
newtype_index! {
45-
/// An index to an [`Expr`] stored in [`Thir::exprs`]
46-
#[derive(HashStable)]
47-
pub struct ExprId {
48-
DEBUG_FORMAT = "e{}"
49-
}
50-
}
51-
52-
newtype_index! {
53-
#[derive(HashStable)]
54-
/// An index to a [`Stmt`] stored in [`Thir::stmts`]
55-
pub struct StmtId {
56-
DEBUG_FORMAT = "s{}"
57-
}
58-
}
59-
6036
macro_rules! thir_with_elements {
61-
($($name:ident: $id:ty => $value:ty,)*) => {
37+
($($name:ident: $id:ty => $value:ty => $format:literal,)*) => {
38+
$(
39+
newtype_index! {
40+
#[derive(HashStable)]
41+
pub struct $id {
42+
DEBUG_FORMAT = $format
43+
}
44+
}
45+
)*
46+
6247
/// A container for a THIR body.
6348
///
6449
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
@@ -91,9 +76,9 @@ macro_rules! thir_with_elements {
9176
}
9277

9378
thir_with_elements! {
94-
arms: ArmId => Arm<'tcx>,
95-
exprs: ExprId => Expr<'tcx>,
96-
stmts: StmtId => Stmt<'tcx>,
79+
arms: ArmId => Arm<'tcx> => "a{}",
80+
exprs: ExprId => Expr<'tcx> => "e{}",
81+
stmts: StmtId => Stmt<'tcx> => "s{}",
9782
}
9883

9984
#[derive(Copy, Clone, Debug, HashStable)]

0 commit comments

Comments
 (0)