Skip to content

Commit a080653

Browse files
committed
Ensure doc link maps have one entry per module.
1 parent ba92291 commit a080653

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14681468
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
14691469
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
14701470
}
1471+
if let DefKind::Mod = tcx.def_kind(def_id) {
1472+
record!(self.tables.doc_link_resolutions[def_id] <- tcx.doc_link_resolutions(def_id));
1473+
record_array!(self.tables.doc_link_traits_in_scope[def_id] <- tcx.doc_link_traits_in_scope(def_id));
1474+
}
14711475
}
14721476

14731477
let inherent_impls = tcx.with_stable_hashing_context(|hcx| {
@@ -1479,14 +1483,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14791483
def_id.index
14801484
}));
14811485
}
1482-
1483-
for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1484-
record!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1485-
}
1486-
1487-
for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1488-
record_array!(self.tables.doc_link_traits_in_scope[def_id.to_def_id()] <- traits);
1489-
}
14901486
}
14911487

14921488
#[instrument(level = "trace", skip(self))]

compiler/rustc_resolve/src/late.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1360,13 +1360,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13601360
}
13611361

13621362
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1363-
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
1363+
let def_id = self.r.local_def_id(id);
1364+
if let Some(module) = self.r.get_module(def_id.to_def_id()) {
13641365
// Move down in the graph.
13651366
let orig_module = replace(&mut self.parent_scope.module, module);
13661367
self.with_rib(ValueNS, RibKind::Module(module), |this| {
13671368
this.with_rib(TypeNS, RibKind::Module(module), |this| {
13681369
let ret = f(this);
13691370
this.parent_scope.module = orig_module;
1371+
this.r.doc_link_resolutions.entry(def_id).or_default();
1372+
this.r.doc_link_traits_in_scope.entry(def_id).or_default();
13701373
ret
13711374
})
13721375
})
@@ -4561,5 +4564,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
45614564
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() {
45624565
self.lint_buffer.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label");
45634566
}
4567+
self.doc_link_resolutions.entry(CRATE_DEF_ID).or_default();
4568+
self.doc_link_traits_in_scope.entry(CRATE_DEF_ID).or_default();
45644569
}
45654570
}

0 commit comments

Comments
 (0)