Skip to content

Commit

Permalink
rustdoc: Fix intra-doc links for cross-crate re-exports of traits
Browse files Browse the repository at this point in the history
 rust-lang#58972 ignored extern_traits because before rust-lang#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.
  • Loading branch information
jyn514 committed Aug 29, 2020
1 parent 1dc748f commit 868927f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,9 @@ pub fn record_extern_trait(cx: &DocContext<'_>, did: DefId) {
}
}

cx.active_extern_traits.borrow_mut().insert(did);
{
cx.active_extern_traits.borrow_mut().insert(did);
}

debug!("record_extern_trait: {:?}", did);
let trait_ = build_external_trait(cx, did);
Expand Down
14 changes: 5 additions & 9 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,11 @@ pub trait DocFolder: Sized {
c.module = c.module.take().and_then(|module| self.fold_item(module));

{
let mut guard = c.external_traits.borrow_mut();
let external_traits = std::mem::replace(&mut *guard, Default::default());
*guard = external_traits
.into_iter()
.map(|(k, mut v)| {
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
(k, v)
})
.collect();
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
for (k, mut v) in external_traits {
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
c.external_traits.borrow_mut().insert(k, v);
}
}
c
}
Expand Down
9 changes: 0 additions & 9 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
self.fold_item_recur(item)
}
}

// FIXME: if we can resolve intra-doc links from other crates, we can use the stock
// `fold_crate`, but until then we should avoid scanning `krate.external_traits` since those
// will never resolve properly
fn fold_crate(&mut self, mut c: Crate) -> Crate {
c.module = c.module.take().and_then(|module| self.fold_item(module));

c
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
2 changes: 0 additions & 2 deletions src/test/rustdoc/intra-doc-crate/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore-test
// ^ this is https://github.com/rust-lang/rust/issues/73829
// aux-build:traits.rs
// build-aux-docs
// ignore-tidy-line-length
Expand Down

0 comments on commit 868927f

Please sign in to comment.