about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-12 02:20:04 +0000
committerbors <bors@rust-lang.org>2020-10-12 02:20:04 +0000
commit1fe9b7f3fe5781a0fdf57d89c39048cb960f3040 (patch)
tree2c8e82ee168c67d2971e6fcea381880c3434e651
parent576e2277acda16dff6293b5c180e7851e6b17d5c (diff)
parent41878285e84f4baf54c5f1d3b566df8459185fde (diff)
downloadrust-1fe9b7f3fe5781a0fdf57d89c39048cb960f3040.tar.gz
rust-1fe9b7f3fe5781a0fdf57d89c39048cb960f3040.zip
Auto merge of #77790 - jyn514:undivided, r=ollie27
Show summary lines on cross-crate re-exports

See my write-up in https://github.com/rust-lang/rust/issues/77783#issuecomment-706551743 for what's going on here.

Fixes https://github.com/rust-lang/rust/issues/77783

r? `@ollie27`
-rw-r--r--src/librustdoc/clean/types.rs31
-rw-r--r--src/librustdoc/passes/collapse_docs.rs5
-rw-r--r--src/test/rustdoc/auxiliary/intra-link-reexport-additional-docs.rs6
-rw-r--r--src/test/rustdoc/auxiliary/reexport-check.rs2
-rw-r--r--src/test/rustdoc/intra-link-reexport-additional-docs.rs9
-rw-r--r--src/test/rustdoc/reexport-check.rs8
6 files changed, 32 insertions, 29 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index 1e07f8e2eac..76efdfc1675 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -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 {
@@ -551,7 +533,7 @@ impl Attributes {
         attrs: &[ast::Attribute],
         additional_attrs: Option<(&[ast::Attribute], DefId)>,
     ) -> Attributes {
-        let doc_strings = RefCell::new(vec![]);
+        let mut doc_strings = vec![];
         let mut sp = None;
         let mut cfg = Cfg::True;
         let mut doc_line = 0;
@@ -568,7 +550,7 @@ impl Attributes {
 
                 let line = doc_line;
                 doc_line += value.lines().count();
-                doc_strings.borrow_mut().push(DocFragment {
+                doc_strings.push(DocFragment {
                     line,
                     span: attr.span,
                     doc: value,
@@ -593,7 +575,7 @@ impl Attributes {
                         {
                             let line = doc_line;
                             doc_line += contents.lines().count();
-                            doc_strings.borrow_mut().push(DocFragment {
+                            doc_strings.push(DocFragment {
                                 line,
                                 span: attr.span,
                                 doc: contents,
@@ -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)
@@ -642,7 +621,7 @@ impl Attributes {
             .map_or(true, |a| a.style == AttrStyle::Inner);
 
         Attributes {
-            doc_strings: doc_strings.into_inner(),
+            doc_strings,
             other_attrs,
             cfg: if cfg == Cfg::True { None } else { Some(Arc::new(cfg)) },
             span: sp,
diff --git a/src/librustdoc/passes/collapse_docs.rs b/src/librustdoc/passes/collapse_docs.rs
index be7250f833f..c2f7f97a673 100644
--- a/src/librustdoc/passes/collapse_docs.rs
+++ b/src/librustdoc/passes/collapse_docs.rs
@@ -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
                 {
diff --git a/src/test/rustdoc/auxiliary/intra-link-reexport-additional-docs.rs b/src/test/rustdoc/auxiliary/intra-link-reexport-additional-docs.rs
new file mode 100644
index 00000000000..fc51995a94e
--- /dev/null
+++ b/src/test/rustdoc/auxiliary/intra-link-reexport-additional-docs.rs
@@ -0,0 +1,6 @@
+#![crate_name = "inner"]
+
+/// Links to [f()]
+pub struct Inner;
+
+pub fn f() {}
diff --git a/src/test/rustdoc/auxiliary/reexport-check.rs b/src/test/rustdoc/auxiliary/reexport-check.rs
new file mode 100644
index 00000000000..672ccb1cf0e
--- /dev/null
+++ b/src/test/rustdoc/auxiliary/reexport-check.rs
@@ -0,0 +1,2 @@
+/// Docs in original
+pub struct S;
diff --git a/src/test/rustdoc/intra-link-reexport-additional-docs.rs b/src/test/rustdoc/intra-link-reexport-additional-docs.rs
index adb072a7ed5..96f3580f305 100644
--- a/src/test/rustdoc/intra-link-reexport-additional-docs.rs
+++ b/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]
@@ -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() {}
diff --git a/src/test/rustdoc/reexport-check.rs b/src/test/rustdoc/reexport-check.rs
index dea72b81a57..066b0cfe5e8 100644
--- a/src/test/rustdoc/reexport-check.rs
+++ b/src/test/rustdoc/reexport-check.rs
@@ -1,5 +1,8 @@
+// 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'
@@ -7,3 +10,8 @@ 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;