Skip to content

Commit 89ae686

Browse files
committed
Ensure doc link maps have one entry per module.
1 parent ff2e6c2 commit 89ae686

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14401440
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
14411441
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
14421442
}
1443+
if let DefKind::Mod = tcx.def_kind(def_id) {
1444+
record!(self.tables.doc_link_resolutions[def_id] <- tcx.doc_link_resolutions(def_id));
1445+
record_array!(self.tables.doc_link_traits_in_scope[def_id] <- tcx.doc_link_traits_in_scope(def_id));
1446+
}
14431447
}
14441448

14451449
let inherent_impls = tcx.with_stable_hashing_context(|hcx| {
@@ -1451,14 +1455,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14511455
def_id.index
14521456
}));
14531457
}
1454-
1455-
for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1456-
record!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1457-
}
1458-
1459-
for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1460-
record_array!(self.tables.doc_link_traits_in_scope[def_id.to_def_id()] <- traits);
1461-
}
14621458
}
14631459

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

compiler/rustc_resolve/src/late.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,13 +1353,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13531353
}
13541354

13551355
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1356-
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
1356+
let def_id = self.r.local_def_id(id);
1357+
if let Some(module) = self.r.get_module(def_id.to_def_id()) {
13571358
// Move down in the graph.
13581359
let orig_module = replace(&mut self.parent_scope.module, module);
13591360
self.with_rib(ValueNS, RibKind::Module(module), |this| {
13601361
this.with_rib(TypeNS, RibKind::Module(module), |this| {
13611362
let ret = f(this);
13621363
this.parent_scope.module = orig_module;
1364+
this.r.doc_link_resolutions.entry(def_id).or_default();
1365+
this.r.doc_link_traits_in_scope.entry(def_id).or_default();
13631366
ret
13641367
})
13651368
})
@@ -4515,5 +4518,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
45154518
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() {
45164519
self.lint_buffer.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label");
45174520
}
4521+
self.doc_link_resolutions.entry(CRATE_DEF_ID).or_default();
4522+
self.doc_link_traits_in_scope.entry(CRATE_DEF_ID).or_default();
45184523
}
45194524
}

0 commit comments

Comments
 (0)