mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-21 04:54:26 +00:00
Rollup merge of #45325 - spastorino:first_statement_index_with_macro, r=nikomatsakis
Generate FirstStatementIndex using newtype_index macro
This commit is contained in:
commit
0d4dbbab46
@ -518,7 +518,7 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
|
||||
FnPtrAddrCast
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { idx });
|
||||
impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
|
||||
impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
|
||||
|
||||
impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for region::Scope {
|
||||
|
@ -156,26 +156,11 @@ pub struct BlockRemainder {
|
||||
pub first_statement_index: FirstStatementIndex,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
|
||||
RustcDecodable, Copy)]
|
||||
pub struct FirstStatementIndex { pub idx: u32 }
|
||||
|
||||
impl Idx for FirstStatementIndex {
|
||||
fn new(idx: usize) -> Self {
|
||||
assert!(idx <= SCOPE_DATA_REMAINDER_MAX as usize);
|
||||
FirstStatementIndex { idx: idx as u32 }
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
self.idx as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for FirstStatementIndex {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.index(), formatter)
|
||||
}
|
||||
}
|
||||
newtype_index!(FirstStatementIndex
|
||||
{
|
||||
DEBUG_NAME = "",
|
||||
MAX = SCOPE_DATA_REMAINDER_MAX,
|
||||
});
|
||||
|
||||
impl From<ScopeData> for Scope {
|
||||
#[inline]
|
||||
@ -208,7 +193,7 @@ impl Scope {
|
||||
SCOPE_DATA_DESTRUCTION => ScopeData::Destruction(self.id),
|
||||
idx => ScopeData::Remainder(BlockRemainder {
|
||||
block: self.id,
|
||||
first_statement_index: FirstStatementIndex { idx }
|
||||
first_statement_index: FirstStatementIndex::new(idx as usize)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ macro_rules! newtype_index {
|
||||
(@type[$type:ident] @max[$max:expr] @debug_name[$debug_name:expr]) => (
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
|
||||
RustcEncodable, RustcDecodable)]
|
||||
pub struct $type(u32);
|
||||
pub struct $type(pub u32);
|
||||
|
||||
impl Idx for $type {
|
||||
fn new(value: usize) -> Self {
|
||||
@ -99,7 +99,7 @@ macro_rules! newtype_index {
|
||||
// Replace existing default for max
|
||||
(@type[$type:ident] @max[$_max:expr] @debug_name[$debug_name:expr]
|
||||
MAX = $max:expr, $($tokens:tt)*) => (
|
||||
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $(tokens)*);
|
||||
newtype_index!(@type[$type] @max[$max] @debug_name[$debug_name] $($tokens)*);
|
||||
);
|
||||
|
||||
// Replace existing default for debug_name
|
||||
|
Loading…
Reference in New Issue
Block a user