diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2016-03-15 11:34:17 +0100 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2016-03-21 18:36:22 +0100 |
| commit | 7d53a25b38b5dfd3e2d60eede247116e2ffff9a2 (patch) | |
| tree | 9bfa191446a8dc481b42307daee40e34bfee10a8 /src | |
| parent | 24ff32748428320cabb74101260fef8facfe4a26 (diff) | |
| download | rust-7d53a25b38b5dfd3e2d60eede247116e2ffff9a2.tar.gz rust-7d53a25b38b5dfd3e2d60eede247116e2ffff9a2.zip | |
factor the wrapped Index newtype definitions into a macro.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_borrowck/borrowck/mir/gather_moves.rs | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/librustc_borrowck/borrowck/mir/gather_moves.rs b/src/librustc_borrowck/borrowck/mir/gather_moves.rs index 135fdb838d0..1b663ef9749 100644 --- a/src/librustc_borrowck/borrowck/mir/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/mir/gather_moves.rs @@ -25,22 +25,32 @@ use std::usize; 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 @@ impl<'tcx> fmt::Debug for MovePath<'tcx> { } } -/// 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>, |
