Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intra-doc links for cross-crate re-exports of default trait methods #75176

Merged
merged 3 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl<'a> CrateLoader<'a> {
let mut ret = None;
self.cstore.iter_crate_data(|cnum, data| {
if data.name() != name {
tracing::trace!("{} did not match {}", data.name(), name);
return;
}

Expand All @@ -230,7 +231,10 @@ impl<'a> CrateLoader<'a> {
ret = Some(cnum);
return;
}
Some(..) => return,
Some(hash) => {
debug!("actual hash {} did not match expected {}", hash, data.hash());
return;
}
None => {}
}

Expand Down Expand Up @@ -273,6 +277,11 @@ impl<'a> CrateLoader<'a> {
.1;
if kind.matches(prev_kind) {
ret = Some(cnum);
} else {
debug!(
"failed to load existing crate {}; kind {:?} did not match prev_kind {:?}",
name, kind, prev_kind
);
}
});
ret
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,12 @@ impl<'a> Resolver<'a> {
Res::Def(DefKind::Mod, _) => true,
_ => false,
};
let mut candidates =
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod);
// Don't look up import candidates if this is a speculative resolve
let mut candidates = if record_used {
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod)
} else {
Vec::new()
};
candidates.sort_by_cached_key(|c| {
(c.path.segments.len(), pprust::path_to_string(&c.path))
});
Expand Down Expand Up @@ -3200,7 +3204,7 @@ impl<'a> Resolver<'a> {
&Segment::from_path(path),
Some(ns),
parent_scope,
true,
false,
path.span,
CrateLint::No,
) {
Expand Down
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
1 change: 1 addition & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ pub fn run_core(
resolver.borrow_mut().access(|resolver| {
sess.time("load_extern_crates", || {
for extern_name in &extern_names {
debug!("loading extern crate {}", extern_name);
resolver
.resolve_str_path_error(
DUMMY_SP,
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
10 changes: 1 addition & 9 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
return Some(res.map_id(|_| panic!("unexpected id")));
}
if let Some(module_id) = parent_id {
debug!("resolving {} as a macro in the module {:?}", path_str, module_id);
if let Ok((_, res)) =
resolver.resolve_str_path_error(DUMMY_SP, path_str, MacroNS, module_id)
{
Expand Down Expand Up @@ -971,15 +972,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