Skip to content

Commit a7c9c64

Browse files
authored
Unrolled build for rust-lang#131691
Rollup merge of rust-lang#131691 - GuillaumeGomez:intra-doc-link-filter-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```
2 parents 7342830 + 10f2395 commit a7c9c64

19 files changed

+351
-56
lines changed

src/librustdoc/clean/types.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1228,15 +1228,14 @@ impl Attributes {
12281228
for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) {
12291229
if let Some(values) = attr.meta_item_list() {
12301230
for l in values {
1231-
match l.lit().unwrap().kind {
1232-
ast::LitKind::Str(s, _) => {
1233-
aliases.insert(s);
1234-
}
1235-
_ => unreachable!(),
1231+
if let Some(lit) = l.lit()
1232+
&& let ast::LitKind::Str(s, _) = lit.kind
1233+
{
1234+
aliases.insert(s);
12361235
}
12371236
}
1238-
} else {
1239-
aliases.insert(attr.value_str().unwrap());
1237+
} else if let Some(value) = attr.value_str() {
1238+
aliases.insert(value);
12401239
}
12411240
}
12421241
aliases.into_iter().collect::<Vec<_>>().into()

src/librustdoc/core.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ use crate::clean::inline::build_external_trait;
2929
use crate::clean::{self, ItemId};
3030
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
3131
use crate::formats::cache::Cache;
32+
use crate::passes;
3233
use crate::passes::Condition::*;
33-
use crate::passes::{self};
34+
use crate::passes::collect_intra_doc_links::LinkCollector;
3435

3536
pub(crate) struct DocContext<'tcx> {
3637
pub(crate) tcx: TyCtxt<'tcx>,
@@ -427,6 +428,9 @@ pub(crate) fn run_global_ctxt(
427428

428429
info!("Executing passes");
429430

431+
let mut visited = FxHashMap::default();
432+
let mut ambiguous = FxIndexMap::default();
433+
430434
for p in passes::defaults(show_coverage) {
431435
let run = match p.condition {
432436
Always => true,
@@ -436,18 +440,30 @@ pub(crate) fn run_global_ctxt(
436440
};
437441
if run {
438442
debug!("running pass {}", p.pass.name);
439-
krate = tcx.sess.time(p.pass.name, || (p.pass.run)(krate, &mut ctxt));
443+
if let Some(run_fn) = p.pass.run {
444+
krate = tcx.sess.time(p.pass.name, || run_fn(krate, &mut ctxt));
445+
} else {
446+
let (k, LinkCollector { visited_links, ambiguous_links, .. }) =
447+
passes::collect_intra_doc_links::collect_intra_doc_links(krate, &mut ctxt);
448+
krate = k;
449+
visited = visited_links;
450+
ambiguous = ambiguous_links;
451+
}
440452
}
441453
}
442454

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

457+
krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
458+
459+
let mut collector =
460+
LinkCollector { cx: &mut ctxt, visited_links: visited, ambiguous_links: ambiguous };
461+
collector.resolve_ambiguities();
462+
445463
if let Some(guar) = tcx.dcx().has_errors() {
446464
return Err(guar);
447465
}
448466

449-
krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
450-
451467
Ok((krate, ctxt.render_options, ctxt.cache))
452468
}
453469

src/librustdoc/passes/calculate_doc_coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::visit::DocVisitor;
2020

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

src/librustdoc/passes/check_doc_test_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::visit::DocVisitor;
2020

2121
pub(crate) const CHECK_DOC_TEST_VISIBILITY: Pass = Pass {
2222
name: "check_doc_test_visibility",
23-
run: check_doc_test_visibility,
23+
run: Some(check_doc_test_visibility),
2424
description: "run various visibility-related lints on doctests",
2525
};
2626

0 commit comments

Comments
 (0)