Skip to content

Commit b8f981a

Browse files
committed
Generate FirstStatementIndex using newtype_index macro
1 parent abe7c87 commit b8f981a

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
518518
FnPtrAddrCast
519519
});
520520

521-
impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { idx });
521+
impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
522522
impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
523523

524524
impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for region::Scope {

src/librustc/middle/region.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,11 @@ pub struct BlockRemainder {
156156
pub first_statement_index: FirstStatementIndex,
157157
}
158158

159-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
160-
RustcDecodable, Copy)]
161-
pub struct FirstStatementIndex { pub idx: u32 }
162-
163-
impl Idx for FirstStatementIndex {
164-
fn new(idx: usize) -> Self {
165-
assert!(idx <= SCOPE_DATA_REMAINDER_MAX as usize);
166-
FirstStatementIndex { idx: idx as u32 }
167-
}
168-
169-
fn index(self) -> usize {
170-
self.idx as usize
171-
}
172-
}
173-
174-
impl fmt::Debug for FirstStatementIndex {
175-
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
176-
fmt::Debug::fmt(&self.index(), formatter)
177-
}
178-
}
159+
newtype_index!(FirstStatementIndex
160+
{
161+
DEBUG_NAME = "",
162+
MAX = SCOPE_DATA_REMAINDER_MAX,
163+
});
179164

180165
impl From<ScopeData> for Scope {
181166
#[inline]
@@ -208,7 +193,7 @@ impl Scope {
208193
SCOPE_DATA_DESTRUCTION => ScopeData::Destruction(self.id),
209194
idx => ScopeData::Remainder(BlockRemainder {
210195
block: self.id,
211-
first_statement_index: FirstStatementIndex { idx }
196+
first_statement_index: FirstStatementIndex::new(idx as usize)
212197
})
213198
}
214199
}

src/librustc_data_structures/indexed_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ macro_rules! newtype_index {
6565
(@type[$type:ident] @max[$max:expr] @debug_name[$debug_name:expr]) => (
6666
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
6767
RustcEncodable, RustcDecodable)]
68-
pub struct $type(u32);
68+
pub struct $type(pub u32);
6969

7070
impl Idx for $type {
7171
fn new(value: usize) -> Self {
@@ -99,7 +99,7 @@ macro_rules! newtype_index {
9999
// Replace existing default for max
100100
(@type[$type:ident] @max[$_max:expr] @debug_name[$debug_name:expr]
101101
MAX = $max:expr, $($tokens:tt)*) => (
102-
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $(tokens)*);
102+
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $($tokens)*);
103103
);
104104

105105
// Replace existing default for debug_name

0 commit comments

Comments
 (0)