Skip to content

Commit 868927f

Browse files
committed
rustdoc: Fix intra-doc links for cross-crate re-exports of traits
#58972 ignored extern_traits because before #65983 was fixed, they would always fail to resolve, giving spurious warnings. This undoes that change, so extern traits are now seen by the `collect_intra_doc_links` pass. There are also some minor changes in librustdoc/fold.rs to avoid borrowing the extern_traits RefCell more than once at a time.
1 parent 1dc748f commit 868927f

File tree

4 files changed

+8
-21
lines changed

4 files changed

+8
-21
lines changed

src/librustdoc/clean/inline.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,9 @@ pub fn record_extern_trait(cx: &DocContext<'_>, did: DefId) {
628628
}
629629
}
630630

631-
cx.active_extern_traits.borrow_mut().insert(did);
631+
{
632+
cx.active_extern_traits.borrow_mut().insert(did);
633+
}
632634

633635
debug!("record_extern_trait: {:?}", did);
634636
let trait_ = build_external_trait(cx, did);

src/librustdoc/fold.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ pub trait DocFolder: Sized {
9393
c.module = c.module.take().and_then(|module| self.fold_item(module));
9494

9595
{
96-
let mut guard = c.external_traits.borrow_mut();
97-
let external_traits = std::mem::replace(&mut *guard, Default::default());
98-
*guard = external_traits
99-
.into_iter()
100-
.map(|(k, mut v)| {
101-
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
102-
(k, v)
103-
})
104-
.collect();
96+
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
97+
for (k, mut v) in external_traits {
98+
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
99+
c.external_traits.borrow_mut().insert(k, v);
100+
}
105101
}
106102
c
107103
}

src/librustdoc/passes/collect_intra_doc_links.rs

-9
Original file line numberDiff line numberDiff line change
@@ -971,15 +971,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
971971
self.fold_item_recur(item)
972972
}
973973
}
974-
975-
// FIXME: if we can resolve intra-doc links from other crates, we can use the stock
976-
// `fold_crate`, but until then we should avoid scanning `krate.external_traits` since those
977-
// will never resolve properly
978-
fn fold_crate(&mut self, mut c: Crate) -> Crate {
979-
c.module = c.module.take().and_then(|module| self.fold_item(module));
980-
981-
c
982-
}
983974
}
984975

985976
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

src/test/rustdoc/intra-doc-crate/traits.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore-test
2-
// ^ this is https://github.com/rust-lang/rust/issues/73829
31
// aux-build:traits.rs
42
// build-aux-docs
53
// ignore-tidy-line-length

0 commit comments

Comments
 (0)