]> git.lizzy.rs Git - rust.git/commitdiff
factor the wrapped Index newtype definitions into a macro.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 15 Mar 2016 10:34:17 +0000 (11:34 +0100)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Mon, 21 Mar 2016 17:36:22 +0000 (18:36 +0100)
src/librustc_borrowck/borrowck/mir/gather_moves.rs

index 135fdb838d087180a3fc06bce1cbae97440c0c40..1b663ef9749b79a758b6db2c5ea754414f1f35b0 100644 (file)
 use super::dataflow::BitDenotation;
 use super::abs_domain::{AbstractElem, Lift};
 
-/// Index into MovePathData.move_paths
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub struct MovePathIndex(usize);
-
-const INVALID_MOVE_PATH_INDEX: MovePathIndex = MovePathIndex(usize::MAX);
-
-impl MovePathIndex {
-    pub fn idx(&self) -> Option<usize> {
-        if *self == INVALID_MOVE_PATH_INDEX {
-            None
-        } else {
-            Some(self.0)
+macro_rules! new_index {
+    ($Index:ident, $INVALID_INDEX:ident) => {
+        #[derive(Copy, Clone, PartialEq, Eq, Debug)]
+        pub struct $Index(usize);
+
+        const $INVALID_INDEX: $Index = $Index(usize::MAX);
+
+        impl $Index {
+            pub fn idx(&self) -> Option<usize> {
+                if *self == $INVALID_INDEX {
+                    None
+                } else {
+                    Some(self.0)
+                }
+            }
         }
     }
 }
 
+/// Index into MovePathData.move_paths
+new_index!(MovePathIndex, INVALID_MOVE_PATH_INDEX);
+
+/// Index into MoveData.moves.
+new_index!(MoveOutIndex, INVALID_MOVE_OUT_INDEX);
+
+
 /// `MovePath` is a canonicalized representation of a path that is
 /// moved or assigned to.
 ///
@@ -99,22 +109,6 @@ fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-/// Index into MoveData.moves.
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub struct MoveOutIndex(usize);
-
-impl MoveOutIndex {
-    pub fn idx(&self) -> Option<usize> {
-        if *self == INVALID_MOVE_OUT_INDEX {
-            None
-        } else {
-            Some(self.0)
-        }
-    }
-}
-
-const INVALID_MOVE_OUT_INDEX: MoveOutIndex = MoveOutIndex(usize::MAX);
-
 pub struct MoveData<'tcx> {
     pub move_paths: MovePathData<'tcx>,
     pub moves: Vec<MoveOut>,