diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-01-13 05:26:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-13 05:26:57 +0100 |
| commit | 8f11da4bfc892c063dbb9109a286178e842d0b52 (patch) | |
| tree | 2db12dd0ba530d2d4723cec4eae7405b809d3488 | |
| parent | ce448f364a0f9180430f55a45287b7cdd5a98ef0 (diff) | |
| parent | ca47808479f7b5eccdbb595c7769ea6009db9a9c (diff) | |
| download | rust-8f11da4bfc892c063dbb9109a286178e842d0b52.tar.gz rust-8f11da4bfc892c063dbb9109a286178e842d0b52.zip | |
Rollup merge of #57508 - DebugSteven:inline-extern, r=GuillaumeGomez
rustdoc: Allow inlining of reexported crates and crate items Fixes #46296 This PR checks for when a `pub extern crate` statement has a `#[doc(inline)]` attribute & inlines its contents. Code is based off of the inlining statements for `pub use` statements.
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 31 | ||||
| -rw-r--r-- | src/test/rustdoc/auxiliary/pub-extern-crate.rs | 2 | ||||
| -rw-r--r-- | src/test/rustdoc/pub-extern-crate.rs | 9 |
3 files changed, 37 insertions, 5 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 37c6407fbd1..6eea95b61c9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -587,7 +587,7 @@ impl Clean<Item> for doctree::Module { let attrs = self.attrs.clean(cx); let mut items: Vec<Item> = vec![]; - items.extend(self.extern_crates.iter().map(|x| x.clean(cx))); + items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx))); items.extend(self.imports.iter().flat_map(|x| x.clean(cx))); items.extend(self.structs.iter().map(|x| x.clean(cx))); items.extend(self.unions.iter().map(|x| x.clean(cx))); @@ -3503,9 +3503,30 @@ fn build_deref_target_impls(cx: &DocContext, } } -impl Clean<Item> for doctree::ExternCrate { - fn clean(&self, cx: &DocContext) -> Item { - Item { +impl Clean<Vec<Item>> for doctree::ExternCrate { + fn clean(&self, cx: &DocContext) -> Vec<Item> { + + let please_inline = self.vis.node.is_pub() && self.attrs.iter().any(|a| { + a.name() == "doc" && match a.meta_item_list() { + Some(l) => attr::list_contains_name(&l, "inline"), + None => false, + } + }); + + if please_inline { + let mut visited = FxHashSet::default(); + + let def = Def::Mod(DefId { + krate: self.cnum, + index: CRATE_DEF_INDEX, + }); + + if let Some(items) = inline::try_inline(cx, def, self.name, &mut visited) { + return items; + } + } + + vec![Item { name: None, attrs: self.attrs.clean(cx), source: self.whence.clean(cx), @@ -3514,7 +3535,7 @@ impl Clean<Item> for doctree::ExternCrate { stability: None, deprecation: None, inner: ExternCrateItem(self.name.clean(cx), self.path.clone()) - } + }] } } diff --git a/src/test/rustdoc/auxiliary/pub-extern-crate.rs b/src/test/rustdoc/auxiliary/pub-extern-crate.rs new file mode 100644 index 00000000000..8c89c8d6c76 --- /dev/null +++ b/src/test/rustdoc/auxiliary/pub-extern-crate.rs @@ -0,0 +1,2 @@ +#![crate_name = "inner"] +pub struct SomeStruct; diff --git a/src/test/rustdoc/pub-extern-crate.rs b/src/test/rustdoc/pub-extern-crate.rs new file mode 100644 index 00000000000..26747a4d1ac --- /dev/null +++ b/src/test/rustdoc/pub-extern-crate.rs @@ -0,0 +1,9 @@ +// aux-build:pub-extern-crate.rs + +// @has pub_extern_crate/index.html +// @!has - '//code' 'pub extern crate inner' +// @has - '//a/@href' 'inner/index.html' +// @has pub_extern_crate/inner/index.html +// @has pub_extern_crate/inner/struct.SomeStruct.html +#[doc(inline)] +pub extern crate inner; |
