@@ -9,14 +9,13 @@ pub use self::UnOp::*;
99pub use self :: UnsafeSource :: * ;
1010
1111use crate :: hir:: def:: { DefKind , Res } ;
12- use crate :: hir:: def_id:: { DefId , DefIndex , LocalDefId , CRATE_DEF_INDEX } ;
12+ use crate :: hir:: def_id:: { DefId , DefIndex } ;
1313use crate :: ty:: query:: Providers ;
1414
1515use errors:: FatalError ;
1616use rustc_data_structures:: fx:: FxHashSet ;
1717use rustc_data_structures:: sync:: { par_for_each_in, Send , Sync } ;
1818use rustc_macros:: HashStable ;
19- use rustc_serialize:: { self , Decodable , Decoder , Encodable , Encoder } ;
2019use rustc_session:: node_id:: NodeMap ;
2120use rustc_span:: source_map:: { SourceMap , Spanned } ;
2221use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -35,96 +34,14 @@ use syntax::util::parser::ExprPrecedence;
3534pub mod check_attr;
3635pub mod def;
3736pub use rustc_hir:: def_id;
37+ pub use rustc_hir:: hir_id:: * ;
3838pub mod intravisit;
3939pub mod itemlikevisit;
4040pub mod map;
4141pub mod pat_util;
4242pub mod print;
4343pub mod upvars;
4444
45- /// Uniquely identifies a node in the HIR of the current crate. It is
46- /// composed of the `owner`, which is the `DefIndex` of the directly enclosing
47- /// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"),
48- /// and the `local_id` which is unique within the given owner.
49- ///
50- /// This two-level structure makes for more stable values: One can move an item
51- /// around within the source code, or add or remove stuff before it, without
52- /// the `local_id` part of the `HirId` changing, which is a very useful property in
53- /// incremental compilation where we have to persist things through changes to
54- /// the code base.
55- #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , PartialOrd , Ord ) ]
56- pub struct HirId {
57- pub owner : DefIndex ,
58- pub local_id : ItemLocalId ,
59- }
60-
61- impl HirId {
62- pub fn owner_def_id ( self ) -> DefId {
63- DefId :: local ( self . owner )
64- }
65-
66- pub fn owner_local_def_id ( self ) -> LocalDefId {
67- LocalDefId :: from_def_id ( DefId :: local ( self . owner ) )
68- }
69- }
70-
71- impl rustc_serialize:: UseSpecializedEncodable for HirId {
72- fn default_encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
73- let HirId { owner, local_id } = * self ;
74-
75- owner. encode ( s) ?;
76- local_id. encode ( s) ?;
77- Ok ( ( ) )
78- }
79- }
80-
81- impl rustc_serialize:: UseSpecializedDecodable for HirId {
82- fn default_decode < D : Decoder > ( d : & mut D ) -> Result < HirId , D :: Error > {
83- let owner = DefIndex :: decode ( d) ?;
84- let local_id = ItemLocalId :: decode ( d) ?;
85-
86- Ok ( HirId { owner, local_id } )
87- }
88- }
89-
90- impl fmt:: Display for HirId {
91- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
92- write ! ( f, "{:?}" , self )
93- }
94- }
95-
96- rustc_data_structures:: define_id_collections!( HirIdMap , HirIdSet , HirId ) ;
97- rustc_data_structures:: define_id_collections!( ItemLocalMap , ItemLocalSet , ItemLocalId ) ;
98-
99- // Hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module.
100- mod item_local_id_inner {
101- use rustc_index:: vec:: Idx ;
102- use rustc_macros:: HashStable ;
103- rustc_index:: newtype_index! {
104- /// An `ItemLocalId` uniquely identifies something within a given "item-like";
105- /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no
106- /// guarantee that the numerical value of a given `ItemLocalId` corresponds to
107- /// the node's position within the owning item in any way, but there is a
108- /// guarantee that the `LocalItemId`s within an owner occupy a dense range of
109- /// integers starting at zero, so a mapping that maps all or most nodes within
110- /// an "item-like" to something else can be implemented by a `Vec` instead of a
111- /// tree or hash map.
112- pub struct ItemLocalId {
113- derive [ HashStable ]
114- }
115- }
116- }
117-
118- pub use self :: item_local_id_inner:: ItemLocalId ;
119-
120- /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
121- pub const CRATE_HIR_ID : HirId =
122- HirId { owner : CRATE_DEF_INDEX , local_id : ItemLocalId :: from_u32_const ( 0 ) } ;
123-
124- pub const DUMMY_HIR_ID : HirId = HirId { owner : CRATE_DEF_INDEX , local_id : DUMMY_ITEM_LOCAL_ID } ;
125-
126- pub const DUMMY_ITEM_LOCAL_ID : ItemLocalId = ItemLocalId :: MAX ;
127-
12845#[ derive( Copy , Clone , RustcEncodable , RustcDecodable , HashStable ) ]
12946pub struct Lifetime {
13047 pub hir_id : HirId ,
0 commit comments