Skip to content

Commit

Permalink
Rollup merge of rust-lang#131691 - GuillaumeGomez:intra-doc-link-filt…
Browse files Browse the repository at this point in the history
…er-out-2, r=notriddle

Delay ambiguous intra-doc link resolution after `Cache` has been populated

Fixes rust-lang#130233.

I was getting nowhere with rust-lang#130278. I took a wrong turn at some point and ended making way too many changes so instead I started again back from 0 and this time it worked out as expected.

r? ``@notriddle``
  • Loading branch information
Urgau authored Oct 16, 2024
2 parents 7ca54f6 + 10f2395 commit 9a49a96
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 56 deletions.
13 changes: 6 additions & 7 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,15 +1228,14 @@ impl Attributes {
for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) {
if let Some(values) = attr.meta_item_list() {
for l in values {
match l.lit().unwrap().kind {
ast::LitKind::Str(s, _) => {
aliases.insert(s);
}
_ => unreachable!(),
if let Some(lit) = l.lit()
&& let ast::LitKind::Str(s, _) = lit.kind
{
aliases.insert(s);
}
}
} else {
aliases.insert(attr.value_str().unwrap());
} else if let Some(value) = attr.value_str() {
aliases.insert(value);
}
}
aliases.into_iter().collect::<Vec<_>>().into()
Expand Down
24 changes: 20 additions & 4 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use crate::clean::inline::build_external_trait;
use crate::clean::{self, ItemId};
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
use crate::formats::cache::Cache;
use crate::passes;
use crate::passes::Condition::*;
use crate::passes::{self};
use crate::passes::collect_intra_doc_links::LinkCollector;

pub(crate) struct DocContext<'tcx> {
pub(crate) tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -427,6 +428,9 @@ pub(crate) fn run_global_ctxt(

info!("Executing passes");

let mut visited = FxHashMap::default();
let mut ambiguous = FxIndexMap::default();

for p in passes::defaults(show_coverage) {
let run = match p.condition {
Always => true,
Expand All @@ -436,18 +440,30 @@ pub(crate) fn run_global_ctxt(
};
if run {
debug!("running pass {}", p.pass.name);
krate = tcx.sess.time(p.pass.name, || (p.pass.run)(krate, &mut ctxt));
if let Some(run_fn) = p.pass.run {
krate = tcx.sess.time(p.pass.name, || run_fn(krate, &mut ctxt));
} else {
let (k, LinkCollector { visited_links, ambiguous_links, .. }) =
passes::collect_intra_doc_links::collect_intra_doc_links(krate, &mut ctxt);
krate = k;
visited = visited_links;
ambiguous = ambiguous_links;
}
}
}

tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc)));

krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));

let mut collector =
LinkCollector { cx: &mut ctxt, visited_links: visited, ambiguous_links: ambiguous };
collector.resolve_ambiguities();

if let Some(guar) = tcx.dcx().has_errors() {
return Err(guar);
}

krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));

Ok((krate, ctxt.render_options, ctxt.cache))
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/calculate_doc_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::visit::DocVisitor;

pub(crate) const CALCULATE_DOC_COVERAGE: Pass = Pass {
name: "calculate-doc-coverage",
run: calculate_doc_coverage,
run: Some(calculate_doc_coverage),
description: "counts the number of items with and without documentation",
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/check_doc_test_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::visit::DocVisitor;

pub(crate) const CHECK_DOC_TEST_VISIBILITY: Pass = Pass {
name: "check_doc_test_visibility",
run: check_doc_test_visibility,
run: Some(check_doc_test_visibility),
description: "run various visibility-related lints on doctests",
};

Expand Down
Loading

0 comments on commit 9a49a96

Please sign in to comment.