@@ -37,7 +37,6 @@ use syntax::util::parser::ExprPrecedence;
37
37
use ty:: AdtKind ;
38
38
use ty:: query:: Providers ;
39
39
40
- use rustc_data_structures:: indexed_vec;
41
40
use rustc_data_structures:: sync:: { ParallelIterator , par_iter, Send , Sync , scope} ;
42
41
use rustc_data_structures:: thin_vec:: ThinVec ;
43
42
@@ -121,48 +120,36 @@ impl serialize::UseSpecializedDecodable for HirId {
121
120
}
122
121
}
123
122
124
-
125
- /// An `ItemLocalId` uniquely identifies something within a given "item-like",
126
- /// that is within a hir::Item, hir::TraitItem, or hir::ImplItem. There is no
127
- /// guarantee that the numerical value of a given `ItemLocalId` corresponds to
128
- /// the node's position within the owning item in any way, but there is a
129
- /// guarantee that the `LocalItemId`s within an owner occupy a dense range of
130
- /// integers starting at zero, so a mapping that maps all or most nodes within
131
- /// an "item-like" to something else can be implement by a `Vec` instead of a
132
- /// tree or hash map.
133
- #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ,
134
- RustcEncodable , RustcDecodable ) ]
135
- pub struct ItemLocalId ( pub u32 ) ;
136
-
137
- impl ItemLocalId {
138
- pub fn as_usize ( & self ) -> usize {
139
- self . 0 as usize
123
+ // hack to ensure that we don't try to access the private parts of `NodeId` in this module
124
+ mod item_local_id_inner {
125
+ use rustc_data_structures:: indexed_vec:: Idx ;
126
+ /// An `ItemLocalId` uniquely identifies something within a given "item-like",
127
+ /// that is within a hir::Item, hir::TraitItem, or hir::ImplItem. There is no
128
+ /// guarantee that the numerical value of a given `ItemLocalId` corresponds to
129
+ /// the node's position within the owning item in any way, but there is a
130
+ /// guarantee that the `LocalItemId`s within an owner occupy a dense range of
131
+ /// integers starting at zero, so a mapping that maps all or most nodes within
132
+ /// an "item-like" to something else can be implement by a `Vec` instead of a
133
+ /// tree or hash map.
134
+ newtype_index ! {
135
+ pub struct ItemLocalId { .. }
140
136
}
141
137
}
142
138
143
- impl indexed_vec:: Idx for ItemLocalId {
144
- fn new ( idx : usize ) -> Self {
145
- debug_assert ! ( ( idx as u32 ) as usize == idx) ;
146
- ItemLocalId ( idx as u32 )
147
- }
148
-
149
- fn index ( self ) -> usize {
150
- self . 0 as usize
151
- }
152
- }
139
+ pub use self :: item_local_id_inner:: ItemLocalId ;
153
140
154
141
/// The `HirId` corresponding to CRATE_NODE_ID and CRATE_DEF_INDEX
155
142
pub const CRATE_HIR_ID : HirId = HirId {
156
143
owner : CRATE_DEF_INDEX ,
157
- local_id : ItemLocalId ( 0 )
144
+ local_id : ItemLocalId :: from_u32_const ( 0 )
158
145
} ;
159
146
160
147
pub const DUMMY_HIR_ID : HirId = HirId {
161
148
owner : CRATE_DEF_INDEX ,
162
149
local_id : DUMMY_ITEM_LOCAL_ID ,
163
150
} ;
164
151
165
- pub const DUMMY_ITEM_LOCAL_ID : ItemLocalId = ItemLocalId ( ! 0 ) ;
152
+ pub const DUMMY_ITEM_LOCAL_ID : ItemLocalId = ItemLocalId :: MAX ;
166
153
167
154
#[ derive( Clone , RustcEncodable , RustcDecodable , Copy ) ]
168
155
pub struct Label {
0 commit comments