Skip to content

Commit 7d53a25

Browse files
committed
factor the wrapped Index newtype definitions into a macro.
1 parent 24ff327 commit 7d53a25

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

src/librustc_borrowck/borrowck/mir/gather_moves.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,32 @@ use std::usize;
2525
use super::dataflow::BitDenotation;
2626
use super::abs_domain::{AbstractElem, Lift};
2727

28-
/// Index into MovePathData.move_paths
29-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
30-
pub struct MovePathIndex(usize);
31-
32-
const INVALID_MOVE_PATH_INDEX: MovePathIndex = MovePathIndex(usize::MAX);
33-
34-
impl MovePathIndex {
35-
pub fn idx(&self) -> Option<usize> {
36-
if *self == INVALID_MOVE_PATH_INDEX {
37-
None
38-
} else {
39-
Some(self.0)
28+
macro_rules! new_index {
29+
($Index:ident, $INVALID_INDEX:ident) => {
30+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
31+
pub struct $Index(usize);
32+
33+
const $INVALID_INDEX: $Index = $Index(usize::MAX);
34+
35+
impl $Index {
36+
pub fn idx(&self) -> Option<usize> {
37+
if *self == $INVALID_INDEX {
38+
None
39+
} else {
40+
Some(self.0)
41+
}
42+
}
4043
}
4144
}
4245
}
4346

47+
/// Index into MovePathData.move_paths
48+
new_index!(MovePathIndex, INVALID_MOVE_PATH_INDEX);
49+
50+
/// Index into MoveData.moves.
51+
new_index!(MoveOutIndex, INVALID_MOVE_OUT_INDEX);
52+
53+
4454
/// `MovePath` is a canonicalized representation of a path that is
4555
/// moved or assigned to.
4656
///
@@ -99,22 +109,6 @@ impl<'tcx> fmt::Debug for MovePath<'tcx> {
99109
}
100110
}
101111

102-
/// Index into MoveData.moves.
103-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
104-
pub struct MoveOutIndex(usize);
105-
106-
impl MoveOutIndex {
107-
pub fn idx(&self) -> Option<usize> {
108-
if *self == INVALID_MOVE_OUT_INDEX {
109-
None
110-
} else {
111-
Some(self.0)
112-
}
113-
}
114-
}
115-
116-
const INVALID_MOVE_OUT_INDEX: MoveOutIndex = MoveOutIndex(usize::MAX);
117-
118112
pub struct MoveData<'tcx> {
119113
pub move_paths: MovePathData<'tcx>,
120114
pub moves: Vec<MoveOut>,

0 commit comments

Comments
 (0)