Skip to content

Commit 3f03297

Browse files
committed
inline pub extern crate statements
1 parent 6ecad33 commit 3f03297

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl Clean<Item> for doctree::Module {
587587
let attrs = self.attrs.clean(cx);
588588

589589
let mut items: Vec<Item> = vec![];
590-
items.extend(self.extern_crates.iter().map(|x| x.clean(cx)));
590+
items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx)));
591591
items.extend(self.imports.iter().flat_map(|x| x.clean(cx)));
592592
items.extend(self.structs.iter().map(|x| x.clean(cx)));
593593
items.extend(self.unions.iter().map(|x| x.clean(cx)));
@@ -3503,9 +3503,30 @@ fn build_deref_target_impls(cx: &DocContext,
35033503
}
35043504
}
35053505

3506-
impl Clean<Item> for doctree::ExternCrate {
3507-
fn clean(&self, cx: &DocContext) -> Item {
3508-
Item {
3506+
impl Clean<Vec<Item>> for doctree::ExternCrate {
3507+
fn clean(&self, cx: &DocContext) -> Vec<Item> {
3508+
3509+
let please_inline = self.vis.node.is_pub() && self.attrs.iter().any(|a| {
3510+
a.name() == "doc" && match a.meta_item_list() {
3511+
Some(l) => attr::list_contains_name(&l, "inline"),
3512+
None => false,
3513+
}
3514+
});
3515+
3516+
if please_inline {
3517+
let mut visited = FxHashSet::default();
3518+
3519+
let def = Def::Mod(DefId {
3520+
krate: self.cnum,
3521+
index: CRATE_DEF_INDEX,
3522+
});
3523+
3524+
if let Some(items) = inline::try_inline(cx, def, self.name, &mut visited) {
3525+
return items;
3526+
}
3527+
}
3528+
3529+
vec![Item {
35093530
name: None,
35103531
attrs: self.attrs.clean(cx),
35113532
source: self.whence.clean(cx),
@@ -3514,7 +3535,7 @@ impl Clean<Item> for doctree::ExternCrate {
35143535
stability: None,
35153536
deprecation: None,
35163537
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
3517-
}
3538+
}]
35183539
}
35193540
}
35203541

0 commit comments

Comments
 (0)