@@ -37,7 +37,6 @@ use syntax::util::parser::ExprPrecedence;
3737use ty:: AdtKind ;
3838use ty:: query:: Providers ;
3939
40- use rustc_data_structures:: indexed_vec;
4140use rustc_data_structures:: sync:: { ParallelIterator , par_iter, Send , Sync , scope} ;
4241use rustc_data_structures:: thin_vec:: ThinVec ;
4342
@@ -121,48 +120,36 @@ impl serialize::UseSpecializedDecodable for HirId {
121120 }
122121}
123122
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 `ItemLocalId` 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 { .. }
140136 }
141137}
142138
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 ;
153140
154141/// The `HirId` corresponding to CRATE_NODE_ID and CRATE_DEF_INDEX
155142pub const CRATE_HIR_ID : HirId = HirId {
156143 owner : CRATE_DEF_INDEX ,
157- local_id : ItemLocalId ( 0 )
144+ local_id : ItemLocalId :: from_u32_const ( 0 )
158145} ;
159146
160147pub const DUMMY_HIR_ID : HirId = HirId {
161148 owner : CRATE_DEF_INDEX ,
162149 local_id : DUMMY_ITEM_LOCAL_ID ,
163150} ;
164151
165- pub const DUMMY_ITEM_LOCAL_ID : ItemLocalId = ItemLocalId ( ! 0 ) ;
152+ pub const DUMMY_ITEM_LOCAL_ID : ItemLocalId = ItemLocalId :: MAX ;
166153
167154#[ derive( Clone , RustcEncodable , RustcDecodable , Copy ) ]
168155pub struct Label {
0 commit comments