@@ -47,9 +47,12 @@ use hir::def_id::{DefIndex, DefId};
47
47
use hir:: def:: { Def , PathResolution } ;
48
48
use session:: Session ;
49
49
use util:: nodemap:: NodeMap ;
50
+ use rustc_data_structures:: fnv:: FnvHashMap ;
50
51
51
52
use std:: collections:: BTreeMap ;
52
53
use std:: iter;
54
+ use std:: mem;
55
+
53
56
use syntax:: ast:: * ;
54
57
use syntax:: errors;
55
58
use syntax:: ptr:: P ;
@@ -68,6 +71,7 @@ pub struct LoweringContext<'a> {
68
71
// the form of a DefIndex) so that if we create a new node which introduces
69
72
// a definition, then we can properly create the def id.
70
73
parent_def : Option < DefIndex > ,
74
+ exprs : FnvHashMap < hir:: ExprId , hir:: Expr > ,
71
75
resolver : & ' a mut Resolver ,
72
76
73
77
/// The items being lowered are collected here.
@@ -104,6 +108,7 @@ pub fn lower_crate(sess: &Session,
104
108
crate_root : std_inject:: injected_crate_name ( krate) ,
105
109
sess : sess,
106
110
parent_def : None ,
111
+ exprs : FnvHashMap ( ) ,
107
112
resolver : resolver,
108
113
items : BTreeMap :: new ( ) ,
109
114
impl_items : BTreeMap :: new ( ) ,
@@ -120,6 +125,23 @@ enum ParamMode {
120
125
121
126
impl < ' a > LoweringContext < ' a > {
122
127
fn lower_crate ( mut self , c : & Crate ) -> hir:: Crate {
128
+ self . lower_items ( c) ;
129
+ let module = self . lower_mod ( & c. module ) ;
130
+ let attrs = self . lower_attrs ( & c. attrs ) ;
131
+ let exported_macros = c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ;
132
+
133
+ hir:: Crate {
134
+ module : module,
135
+ attrs : attrs,
136
+ span : c. span ,
137
+ exported_macros : exported_macros,
138
+ items : self . items ,
139
+ impl_items : self . impl_items ,
140
+ exprs : mem:: replace ( & mut self . exprs , FnvHashMap ( ) ) ,
141
+ }
142
+ }
143
+
144
+ fn lower_items ( & mut self , c : & Crate ) {
123
145
struct ItemLowerer < ' lcx , ' interner : ' lcx > {
124
146
lctx : & ' lcx mut LoweringContext < ' interner > ,
125
147
}
@@ -139,16 +161,14 @@ impl<'a> LoweringContext<'a> {
139
161
}
140
162
}
141
163
142
- visit:: walk_crate ( & mut ItemLowerer { lctx : & mut self } , c) ;
164
+ let mut item_lowerer = ItemLowerer { lctx : self } ;
165
+ visit:: walk_crate ( & mut item_lowerer, c) ;
166
+ }
143
167
144
- hir:: Crate {
145
- module : self . lower_mod ( & c. module ) ,
146
- attrs : self . lower_attrs ( & c. attrs ) ,
147
- span : c. span ,
148
- exported_macros : c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ,
149
- items : self . items ,
150
- impl_items : self . impl_items ,
151
- }
168
+ fn record_expr ( & mut self , expr : hir:: Expr ) -> hir:: ExprId {
169
+ let id = hir:: ExprId ( expr. id ) ;
170
+ self . exprs . insert ( id, expr) ;
171
+ id
152
172
}
153
173
154
174
fn next_id ( & self ) -> NodeId {
0 commit comments