Skip to content

Commit 1fe9b7f

Browse files
committed
Auto merge of #77790 - jyn514:undivided, r=ollie27
Show summary lines on cross-crate re-exports See my write-up in #77783 (comment) for what's going on here. Fixes #77783 r? `@ollie27`
2 parents 576e227 + 4187828 commit 1fe9b7f

6 files changed

+32
-29
lines changed

src/librustdoc/clean/types.rs

+5-26
Original file line numberDiff line numberDiff line change
@@ -393,24 +393,6 @@ pub enum DocFragmentKind {
393393
/// A doc fragment created from a `#[doc(include="filename")]` attribute. Contains both the
394394
/// given filename and the file contents.
395395
Include { filename: String },
396-
/// A doc fragment used to distinguish between documentation in different modules.
397-
///
398-
/// In particular, this prevents `collapse_docs` from turning all documentation comments
399-
/// into a single giant attributes even when the item is re-exported with documentation on the re-export.
400-
Divider,
401-
}
402-
403-
impl DocFragment {
404-
/// Creates a dummy doc-fragment which divides earlier and later fragments.
405-
fn divider() -> Self {
406-
DocFragment {
407-
line: 0,
408-
span: DUMMY_SP,
409-
parent_module: None,
410-
doc: String::new(),
411-
kind: DocFragmentKind::Divider,
412-
}
413-
}
414396
}
415397

416398
impl<'a> FromIterator<&'a DocFragment> for String {
@@ -551,7 +533,7 @@ impl Attributes {
551533
attrs: &[ast::Attribute],
552534
additional_attrs: Option<(&[ast::Attribute], DefId)>,
553535
) -> Attributes {
554-
let doc_strings = RefCell::new(vec![]);
536+
let mut doc_strings = vec![];
555537
let mut sp = None;
556538
let mut cfg = Cfg::True;
557539
let mut doc_line = 0;
@@ -568,7 +550,7 @@ impl Attributes {
568550

569551
let line = doc_line;
570552
doc_line += value.lines().count();
571-
doc_strings.borrow_mut().push(DocFragment {
553+
doc_strings.push(DocFragment {
572554
line,
573555
span: attr.span,
574556
doc: value,
@@ -593,7 +575,7 @@ impl Attributes {
593575
{
594576
let line = doc_line;
595577
doc_line += contents.lines().count();
596-
doc_strings.borrow_mut().push(DocFragment {
578+
doc_strings.push(DocFragment {
597579
line,
598580
span: attr.span,
599581
doc: contents,
@@ -610,10 +592,7 @@ impl Attributes {
610592
// Additional documentation should be shown before the original documentation
611593
let other_attrs = additional_attrs
612594
.into_iter()
613-
.map(|(attrs, id)| {
614-
doc_strings.borrow_mut().push(DocFragment::divider());
615-
attrs.iter().map(move |attr| (attr, Some(id)))
616-
})
595+
.map(|(attrs, id)| attrs.iter().map(move |attr| (attr, Some(id))))
617596
.flatten()
618597
.chain(attrs.iter().map(|attr| (attr, None)))
619598
.filter_map(clean_attr)
@@ -642,7 +621,7 @@ impl Attributes {
642621
.map_or(true, |a| a.style == AttrStyle::Inner);
643622

644623
Attributes {
645-
doc_strings: doc_strings.into_inner(),
624+
doc_strings,
646625
other_attrs,
647626
cfg: if cfg == Cfg::True { None } else { Some(Arc::new(cfg)) },
648627
span: sp,

src/librustdoc/passes/collapse_docs.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fn collapse(doc_strings: &mut Vec<DocFragment>) {
3636
let curr_kind = &curr_frag.kind;
3737
let new_kind = &frag.kind;
3838

39-
if matches!(*curr_kind, DocFragmentKind::Include { .. }) || curr_kind != new_kind {
39+
if matches!(*curr_kind, DocFragmentKind::Include { .. })
40+
|| curr_kind != new_kind
41+
|| curr_frag.parent_module != frag.parent_module
42+
{
4043
if *curr_kind == DocFragmentKind::SugaredDoc
4144
|| *curr_kind == DocFragmentKind::RawDoc
4245
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_name = "inner"]
2+
3+
/// Links to [f()]
4+
pub struct Inner;
5+
6+
pub fn f() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// Docs in original
2+
pub struct S;

src/test/rustdoc/intra-link-reexport-additional-docs.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// aux-build:intra-link-reexport-additional-docs.rs
2+
// build-aux-docs
13
#![crate_name = "foo"]
4+
extern crate inner;
25

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

1621
pub fn with_code() {}
1722
pub fn me_too() {}

src/test/rustdoc/reexport-check.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
// aux-build:reexport-check.rs
12
#![crate_name = "foo"]
23

4+
extern crate reexport_check;
5+
36
// @!has 'foo/index.html' '//code' 'pub use self::i32;'
47
// @has 'foo/index.html' '//tr[@class="module-item"]' 'i32'
58
// @has 'foo/i32/index.html'
69
pub use std::i32;
710
// @!has 'foo/index.html' '//code' 'pub use self::string::String;'
811
// @has 'foo/index.html' '//tr[@class="module-item"]' 'String'
912
pub use std::string::String;
13+
14+
// @has 'foo/index.html' '//td[@class="docblock-short"]' 'Docs in original'
15+
// this is a no-op, but shows what happens if there's an attribute that isn't a doc-comment
16+
#[doc(inline)]
17+
pub use reexport_check::S;

0 commit comments

Comments
 (0)