]> git.lizzy.rs Git - rust.git/commitdiff
Define index types within `thir_with_elements`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Wed, 24 Aug 2022 00:46:27 +0000 (10:46 +1000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Wed, 24 Aug 2022 01:37:56 +0000 (11:37 +1000)
The macro already generates other stuff, might as well generate these
index types as well.

compiler/rustc_middle/src/thir.rs

index 5e26a52900eaf404ce2e4f819ddaf64bd116f7f6..9cb6763b663e580583b3d9294d9f5dffb6f54643 100644 (file)
 
 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 {
-    ($($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.
         ///
         /// This can be indexed directly by any THIR index (e.g. [`ExprId`]).
@@ -91,9 +76,9 @@ fn index(&self, index: $id) -> &Self::Output {
 }
 
 thir_with_elements! {
-    arms: ArmId => Arm<'tcx>,
-    exprs: ExprId => Expr<'tcx>,
-    stmts: StmtId => Stmt<'tcx>,
+    arms: ArmId => Arm<'tcx> => "a{}",
+    exprs: ExprId => Expr<'tcx> => "e{}",
+    stmts: StmtId => Stmt<'tcx> => "s{}",
 }
 
 #[derive(Copy, Clone, Debug, HashStable)]