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 link ICE when trying to get traits in scope for primitive #95645

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
8 changes: 7 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ fn main_options(options: config::Options) -> MainResult {
let externs = options.externs.clone();
let render_options = options.render_options.clone();
let scrape_examples_options = options.scrape_examples_options.clone();
let document_private = options.render_options.document_private;
let config = core::create_config(options);

interface::create_compiler_and_run(config, |compiler| {
Expand All @@ -791,7 +792,12 @@ fn main_options(options: config::Options) -> MainResult {
let (resolver, resolver_caches) = {
let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek();
let resolver_caches = resolver.borrow_mut().access(|resolver| {
collect_intra_doc_links::early_resolve_intra_doc_links(resolver, krate, externs)
collect_intra_doc_links::early_resolve_intra_doc_links(
resolver,
krate,
externs,
document_private,
)
});
(resolver.clone(), resolver_caches)
};
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ crate fn early_resolve_intra_doc_links(
resolver: &mut Resolver<'_>,
krate: &ast::Crate,
externs: Externs,
document_private_items: bool,
) -> ResolverCaches {
let mut loader = IntraLinkCrateLoader {
resolver,
Expand All @@ -30,6 +31,7 @@ crate fn early_resolve_intra_doc_links(
traits_in_scope: Default::default(),
all_traits: Default::default(),
all_trait_impls: Default::default(),
document_private_items,
};

// Because of the `crate::` prefix, any doc comment can reference
Expand Down Expand Up @@ -66,6 +68,7 @@ struct IntraLinkCrateLoader<'r, 'ra> {
traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
all_traits: Vec<DefId>,
all_trait_impls: Vec<DefId>,
document_private_items: bool,
}

impl IntraLinkCrateLoader<'_, '_> {
Expand Down Expand Up @@ -175,7 +178,7 @@ impl IntraLinkCrateLoader<'_, '_> {
}

for child in self.resolver.module_children_or_reexports(module_id) {
if child.vis == Visibility::Public {
if child.vis == Visibility::Public || self.document_private_items {
if let Some(def_id) = child.res.opt_def_id() {
self.add_traits_in_parent_scope(def_id);
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc/issue-95633.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-flags: --document-private-items

// This ensures that no ICE is triggered when rustdoc is run on this code.

mod stdlib {
pub (crate) use std::i8;
}