Skip to content

Commit 6f8d31d

Browse files
committed
---
yaml --- r: 11996 b: refs/heads/master c: 1695148 h: refs/heads/master v: v3
1 parent ce3b593 commit 6f8d31d

File tree

2 files changed

+51
-67
lines changed

2 files changed

+51
-67
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 651aeea96139d5f973410bc3405593c759c3f938
2+
refs/heads/master: 1695148b5de9e801c4fbbbadce2f576e511c1cc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/reexport_pass.rs

Lines changed: 50 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import rustc::util::common;
99
import rustc::middle::ast_map;
1010
import rustc::syntax::visit;
1111
import rustc::syntax::codemap;
12+
import rustc::middle::resolve;
1213

1314
export mk_pass;
1415

@@ -98,50 +99,10 @@ fn build_reexport_def_set(srv: astsrv::srv) -> def_set {
9899

99100
fn find_reexport_impls(ctxt: astsrv::ctxt) -> [ast::def_id] {
100101
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]
131104
}
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;
145106
}
146107

147108
fn build_reexport_def_map(
@@ -264,18 +225,46 @@ fn find_reexport_impl_docs(
264225
def_map: def_map
265226
) -> [(str, (str, doc::itemtag))] {
266227
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+
) {
267258
let visitor = @{
268-
visit_mod: bind visit_mod(ctxt, def_map, docs, _, _, _)
259+
visit_mod: bind visit_mod(ctxt, f, _, _, _)
269260
with *visit::default_simple_visitor()
270261
};
271262
let visitor = visit::mk_simple_visitor(visitor);
272263
visit::visit_crate(*ctxt.ast, (), visitor);
273-
ret *docs;
274264

275265
fn visit_mod(
276266
ctxt: astsrv::ctxt,
277-
def_map: def_map,
278-
docs: @mut [(str, (str, doc::itemtag))],
267+
f: fn@(ast::node_id, resolve::_impl),
279268
m: ast::_mod,
280269
_sp: codemap::span,
281270
mod_id: ast::node_id
@@ -289,25 +278,7 @@ fn find_reexport_impl_docs(
289278
// Ignore external impls because I don't
290279
// know what to do with them yet
291280
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);
311282
}
312283
}
313284
}
@@ -316,6 +287,19 @@ fn find_reexport_impl_docs(
316287
}
317288
}
318289

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+
319303
fn merge_reexports(
320304
doc: doc::doc,
321305
path_map: path_map

0 commit comments

Comments
 (0)