Define index types within thir_with_elements
.
The macro already generates other stuff, might as well generate these index types as well.
This commit is contained in:
parent
a1bea1551b
commit
c9429b1cec
1 changed files with 13 additions and 28 deletions
|
@ -33,32 +33,17 @@ use std::ops::Index;
|
||||||
|
|
||||||
pub mod visit;
|
pub mod visit;
|
||||||
|
|
||||||
newtype_index! {
|
|
||||||
/// An index to an [`Arm`] stored in [`Thir::arms`]
|
|
||||||
#[derive(HashStable)]
|
|
||||||
pub struct ArmId {
|
|
||||||
DEBUG_FORMAT = "a{}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newtype_index! {
|
|
||||||
/// An index to an [`Expr`] stored in [`Thir::exprs`]
|
|
||||||
#[derive(HashStable)]
|
|
||||||
pub struct ExprId {
|
|
||||||
DEBUG_FORMAT = "e{}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newtype_index! {
|
|
||||||
#[derive(HashStable)]
|
|
||||||
/// An index to a [`Stmt`] stored in [`Thir::stmts`]
|
|
||||||
pub struct StmtId {
|
|
||||||
DEBUG_FORMAT = "s{}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! thir_with_elements {
|
macro_rules! thir_with_elements {
|
||||||
($($name:ident: $id:ty => $value:ty,)*) => {
|
($($name:ident: $id:ty => $value:ty => $format:literal,)*) => {
|
||||||
|
$(
|
||||||
|
newtype_index! {
|
||||||
|
#[derive(HashStable)]
|
||||||
|
pub struct $id {
|
||||||
|
DEBUG_FORMAT = $format
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
/// A container for a THIR body.
|
/// A container for a THIR body.
|
||||||
///
|
///
|
||||||
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
|
/// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
|
||||||
|
@ -91,9 +76,9 @@ macro_rules! thir_with_elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
thir_with_elements! {
|
thir_with_elements! {
|
||||||
arms: ArmId => Arm<'tcx>,
|
arms: ArmId => Arm<'tcx> => "a{}",
|
||||||
exprs: ExprId => Expr<'tcx>,
|
exprs: ExprId => Expr<'tcx> => "e{}",
|
||||||
stmts: StmtId => Stmt<'tcx>,
|
stmts: StmtId => Stmt<'tcx> => "s{}",
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, HashStable)]
|
#[derive(Copy, Clone, Debug, HashStable)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue