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

rustdoc: load the set of in-scope traits for modules with no docstring #93441

Merged
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
1 change: 1 addition & 0 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ fn trait_assoc_to_impl_assoc_item<'tcx>(
///
/// NOTE: this cannot be a query because more traits could be available when more crates are compiled!
/// So it is not stable to serialize cross-crate.
#[instrument(level = "debug", skip(cx))]
fn trait_impls_for<'a>(
cx: &mut DocContext<'a>,
ty: Ty<'a>,
Expand Down
10 changes: 10 additions & 0 deletions src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ crate fn early_resolve_intra_doc_links(
all_trait_impls: Default::default(),
};

// Because of the `crate::` prefix, any doc comment can reference
// the crate root's set of in-scope traits. This line makes sure
// it's available.
loader.add_traits_in_scope(CRATE_DEF_ID.to_def_id());

// Overridden `visit_item` below doesn't apply to the crate root,
// so we have to visit its attributes and reexports separately.
loader.load_links_in_attrs(&krate.attrs, krate.span);
Expand Down Expand Up @@ -180,6 +185,11 @@ impl Visitor<'_> for IntraLinkCrateLoader<'_, '_> {
if let ItemKind::Mod(..) = item.kind {
let old_mod = mem::replace(&mut self.current_mod, self.resolver.local_def_id(item.id));

// A module written with a outline doc comments will resolve traits relative
// to the parent module. Make sure the parent module's traits-in-scope are
// loaded, even if the module itself has no doc comments.
self.add_traits_in_parent_scope(self.current_mod.to_def_id());

self.load_links_in_attrs(&item.attrs, item.span);
self.process_module_children_or_reexports(self.current_mod.to_def_id());
visit::walk_item(self, item);
Expand Down
13 changes: 13 additions & 0 deletions src/test/rustdoc/intra-doc/crate-relative.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub struct Test<'a> {
data: &'a (),
}

impl<'a> Test<'a> {
pub fn do_test(&self) {}
}

// @has crate_relative/demo/index.html
// @has - '//a/@href' '../struct.Test.html#method.do_test'
pub mod demo {
//! [`crate::Test::do_test`]
}
17 changes: 17 additions & 0 deletions src/test/rustdoc/intra-doc/mod-relative.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod wrapper {

pub struct Test<'a> {
data: &'a (),
}

impl<'a> Test<'a> {
pub fn do_test(&self) {}
}

// @has mod_relative/wrapper/demo/index.html
// @has - '//a/@href' '../struct.Test.html#method.do_test'
/// [`Test::do_test`]
pub mod demo {
}

}