Skip to content

Commit

Permalink
factor the wrapped Index newtype definitions into a macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Mar 21, 2016
1 parent 24ff327 commit 7d53a25
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/librustc_borrowck/borrowck/mir/gather_moves.rs
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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>,
Expand Down

0 comments on commit 7d53a25

Please sign in to comment.