@@ -9,6 +9,7 @@ import rustc::util::common;
9
9
import rustc:: middle:: ast_map;
10
10
import rustc:: syntax:: visit;
11
11
import rustc:: syntax:: codemap;
12
+ import rustc:: middle:: resolve;
12
13
13
14
export mk_pass;
14
15
@@ -98,50 +99,10 @@ fn build_reexport_def_set(srv: astsrv::srv) -> def_set {
98
99
99
100
fn find_reexport_impls ( ctxt : astsrv:: ctxt ) -> [ ast:: def_id ] {
100
101
let defs = @mut [ ] ;
101
- let visitor = @{
102
- visit_mod: bind visit_mod ( ctxt, defs, _, _, _)
103
- with * visit:: default_simple_visitor ( )
104
- } ;
105
- let visitor = visit:: mk_simple_visitor ( visitor) ;
106
- visit:: visit_crate ( * ctxt. ast , ( ) , visitor) ;
107
- ret * defs;
108
-
109
- fn visit_mod (
110
- ctxt : astsrv:: ctxt ,
111
- defs : @mut [ ast:: def_id ] ,
112
- m : ast:: _mod ,
113
- _sp : codemap:: span ,
114
- mod_id : ast:: node_id
115
- ) {
116
- let all_impls = all_impls ( m) ;
117
- alt check ctxt. impl_map . get ( mod_id) {
118
- list:: cons ( impls, @list:: nil) {
119
- for i in * impls {
120
- // This impl is not an item in the current mod
121
- if !all_impls. contains_key ( i. did ) {
122
- // Ignore external impls because I don't
123
- // know what to do with them yet
124
- if i. did . crate == ast:: local_crate {
125
- * defs += [ i. did ]
126
- }
127
- }
128
- }
129
- }
130
- }
102
+ for_each_reexported_impl ( ctxt) { |_mod_id, i|
103
+ * defs += [ i. did ]
131
104
}
132
- }
133
-
134
- fn all_impls ( m : ast:: _mod ) -> map:: set < ast:: def_id > {
135
- let all_impls = common:: new_def_hash ( ) ;
136
- for item in m. items {
137
- alt item. node {
138
- ast:: item_impl ( _, _, _, _) {
139
- all_impls. insert ( ast_util:: local_def ( item. id ) , ( ) ) ;
140
- }
141
- _ { }
142
- }
143
- }
144
- ret all_impls;
105
+ ret * defs;
145
106
}
146
107
147
108
fn build_reexport_def_map (
@@ -264,18 +225,46 @@ fn find_reexport_impl_docs(
264
225
def_map : def_map
265
226
) -> [ ( str , ( str , doc:: itemtag ) ) ] {
266
227
let docs = @mut [ ] ;
228
+
229
+ for_each_reexported_impl ( ctxt) { |mod_id, i|
230
+ let path = alt ctxt. ast_map . find ( mod_id) {
231
+ some ( ast_map:: node_item ( item, path) ) {
232
+ let path = ast_map:: path_to_str ( * path) ;
233
+ if str:: is_empty ( path) {
234
+ item. ident
235
+ } else {
236
+ path + "::" + item. ident
237
+ }
238
+ }
239
+ _ {
240
+ assert mod_id == ast:: crate_node_id;
241
+ ""
242
+ }
243
+ } ;
244
+ let ident = i. ident ;
245
+ let doc = alt check def_map. find ( i. did ) {
246
+ some ( doc) { doc }
247
+ } ;
248
+ * docs += [ ( path, ( ident, doc) ) ] ;
249
+ }
250
+
251
+ ret * docs;
252
+ }
253
+
254
+ fn for_each_reexported_impl (
255
+ ctxt : astsrv:: ctxt ,
256
+ f : fn @( ast:: node_id , resolve:: _impl )
257
+ ) {
267
258
let visitor = @{
268
- visit_mod: bind visit_mod ( ctxt, def_map , docs , _, _, _)
259
+ visit_mod: bind visit_mod ( ctxt, f , _, _, _)
269
260
with * visit:: default_simple_visitor ( )
270
261
} ;
271
262
let visitor = visit:: mk_simple_visitor ( visitor) ;
272
263
visit:: visit_crate ( * ctxt. ast , ( ) , visitor) ;
273
- ret * docs;
274
264
275
265
fn visit_mod (
276
266
ctxt : astsrv:: ctxt ,
277
- def_map : def_map ,
278
- docs : @mut [ ( str , ( str , doc:: itemtag ) ) ] ,
267
+ f : fn @( ast:: node_id , resolve:: _impl ) ,
279
268
m : ast:: _mod ,
280
269
_sp : codemap:: span ,
281
270
mod_id : ast:: node_id
@@ -289,25 +278,7 @@ fn find_reexport_impl_docs(
289
278
// Ignore external impls because I don't
290
279
// know what to do with them yet
291
280
if i. did . crate == ast:: local_crate {
292
- let path = alt ctxt. ast_map . find ( mod_id) {
293
- some ( ast_map:: node_item ( item, path) ) {
294
- let path = ast_map:: path_to_str ( * path) ;
295
- if str:: is_empty ( path) {
296
- item. ident
297
- } else {
298
- path + "::" + item. ident
299
- }
300
- }
301
- _ {
302
- assert mod_id == ast:: crate_node_id;
303
- ""
304
- }
305
- } ;
306
- let ident = i. ident ;
307
- let doc = alt check def_map. find ( i. did ) {
308
- some ( doc) { doc }
309
- } ;
310
- * docs += [ ( path, ( ident, doc) ) ] ;
281
+ f ( mod_id, * i) ;
311
282
}
312
283
}
313
284
}
@@ -316,6 +287,19 @@ fn find_reexport_impl_docs(
316
287
}
317
288
}
318
289
290
+ fn all_impls ( m : ast:: _mod ) -> map:: set < ast:: def_id > {
291
+ let all_impls = common:: new_def_hash ( ) ;
292
+ for item in m. items {
293
+ alt item. node {
294
+ ast:: item_impl ( _, _, _, _) {
295
+ all_impls. insert ( ast_util:: local_def ( item. id ) , ( ) ) ;
296
+ }
297
+ _ { }
298
+ }
299
+ }
300
+ ret all_impls;
301
+ }
302
+
319
303
fn merge_reexports (
320
304
doc : doc:: doc ,
321
305
path_map : path_map
0 commit comments