Skip to content

Commit

Permalink
Show summary lines on cross-crate re-exports
Browse files Browse the repository at this point in the history
This removes the unnecessary `DocFragmentKind::Divider` in favor of just
using the logic I actually want in `collapse_docs`.
  • Loading branch information
jyn514 committed Oct 12, 2020
1 parent c38f001 commit 1772f2d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
23 changes: 1 addition & 22 deletions src/librustdoc/clean/types.rs
Expand Up @@ -393,24 +393,6 @@ pub enum DocFragmentKind {
/// A doc fragment created from a `#[doc(include="filename")]` attribute. Contains both the
/// given filename and the file contents.
Include { filename: String },
/// A doc fragment used to distinguish between documentation in different modules.
///
/// In particular, this prevents `collapse_docs` from turning all documentation comments
/// into a single giant attributes even when the item is re-exported with documentation on the re-export.
Divider,
}

impl DocFragment {
/// Creates a dummy doc-fragment which divides earlier and later fragments.
fn divider() -> Self {
DocFragment {
line: 0,
span: DUMMY_SP,
parent_module: None,
doc: String::new(),
kind: DocFragmentKind::Divider,
}
}
}

impl<'a> FromIterator<&'a DocFragment> for String {
Expand Down Expand Up @@ -610,10 +592,7 @@ impl Attributes {
// Additional documentation should be shown before the original documentation
let other_attrs = additional_attrs
.into_iter()
.map(|(attrs, id)| {
doc_strings.borrow_mut().push(DocFragment::divider());
attrs.iter().map(move |attr| (attr, Some(id)))
})
.map(|(attrs, id)| attrs.iter().map(move |attr| (attr, Some(id))))
.flatten()
.chain(attrs.iter().map(|attr| (attr, None)))
.filter_map(clean_attr)
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/passes/collapse_docs.rs
Expand Up @@ -36,7 +36,10 @@ fn collapse(doc_strings: &mut Vec<DocFragment>) {
let curr_kind = &curr_frag.kind;
let new_kind = &frag.kind;

if matches!(*curr_kind, DocFragmentKind::Include { .. }) || curr_kind != new_kind {
if matches!(*curr_kind, DocFragmentKind::Include { .. })
|| curr_kind != new_kind
|| curr_frag.parent_module != frag.parent_module
{
if *curr_kind == DocFragmentKind::SugaredDoc
|| *curr_kind == DocFragmentKind::RawDoc
{
Expand Down
@@ -0,0 +1,6 @@
#![crate_name = "inner"]

/// Links to [f()]
pub struct Inner;

pub fn f() {}
2 changes: 2 additions & 0 deletions src/test/rustdoc/auxiliary/reexport-check.rs
@@ -0,0 +1,2 @@
/// Docs in original
pub struct S;
9 changes: 7 additions & 2 deletions src/test/rustdoc/intra-link-reexport-additional-docs.rs
@@ -1,6 +1,9 @@
// aux-build:intra-link-reexport-additional-docs.rs
// build-aux-docs
#![crate_name = "foo"]
extern crate inner;

// @has foo/struct.JoinPathsError.html '//a[@href="../foo/fn.with_code.html"]' 'crate::with_code'
// @has foo/struct.Inner.html '//a[@href="../foo/fn.with_code.html"]' 'crate::with_code'
/// [crate::with_code]
// @has - '//a[@href="../foo/fn.with_code.html"]' 'different text'
/// [different text][with_code]
Expand All @@ -11,7 +14,9 @@
#[doc = "has an attr in the way"]
///
/// [reference link]: me_three
pub use std::env::JoinPathsError;
// Should still resolve links from the original module in that scope
// @has - '//a[@href="../inner/fn.f.html"]' 'f()'
pub use inner::Inner;

pub fn with_code() {}
pub fn me_too() {}
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc/reexport-check.rs
@@ -1,9 +1,17 @@
// aux-build:reexport-check.rs
#![crate_name = "foo"]

extern crate reexport_check;

// @!has 'foo/index.html' '//code' 'pub use self::i32;'
// @has 'foo/index.html' '//tr[@class="module-item"]' 'i32'
// @has 'foo/i32/index.html'
pub use std::i32;
// @!has 'foo/index.html' '//code' 'pub use self::string::String;'
// @has 'foo/index.html' '//tr[@class="module-item"]' 'String'
pub use std::string::String;

// @has 'foo/index.html' '//td[@class="docblock-short"]' 'Docs in original'
// this is a no-op, but shows what happens if there's an attribute that isn't a doc-comment
#[doc(inline)]
pub use reexport_check::S;

0 comments on commit 1772f2d

Please sign in to comment.