Skip to content

Commit 1a41507

Browse files
authored
Rollup merge of rust-lang#72781 - marmeladema:rustdoc-def-id-resolve-str-path-error, r=petrochenkov
Use `LocalDefId` instead of `NodeId` in `resolve_str_path_error` Together with rust-lang#72777 this should remove all uses of `NodeId` in `rustdoc`. cc rust-lang#50928 r? @petrochenkov
2 parents 1d4b5e2 + 372ba2a commit 1a41507

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/librustc_resolve/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,7 @@ impl<'a> Resolver<'a> {
29022902
span: Span,
29032903
path_str: &str,
29042904
ns: Namespace,
2905-
module_id: NodeId,
2905+
module_id: LocalDefId,
29062906
) -> Result<(ast::Path, Res), ()> {
29072907
let path = if path_str.starts_with("::") {
29082908
ast::Path {
@@ -2922,10 +2922,7 @@ impl<'a> Resolver<'a> {
29222922
.collect(),
29232923
}
29242924
};
2925-
let module = self.block_map.get(&module_id).copied().unwrap_or_else(|| {
2926-
let def_id = self.definitions.local_def_id(module_id);
2927-
self.module_map.get(&def_id).copied().unwrap_or(self.graph_root)
2928-
});
2925+
let module = self.module_map.get(&module_id).copied().unwrap_or(self.graph_root);
29292926
let parent_scope = &ParentScope::module(module);
29302927
let res = self.resolve_ast_path(&path, ns, parent_scope).map_err(|_| ())?;
29312928
Ok((path, res))

src/librustdoc/core.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_ast::ast::CRATE_NODE_ID;
21
use rustc_attr as attr;
32
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
43
use rustc_data_structures::sync::{self, Lrc};
@@ -7,7 +6,7 @@ use rustc_errors::emitter::{Emitter, EmitterWriter};
76
use rustc_errors::json::JsonEmitter;
87
use rustc_feature::UnstableFeatures;
98
use rustc_hir::def::Namespace::TypeNS;
10-
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
9+
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1110
use rustc_hir::HirId;
1211
use rustc_interface::interface;
1312
use rustc_middle::middle::cstore::CrateStore;
@@ -390,7 +389,12 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
390389
resolver.borrow_mut().access(|resolver| {
391390
for extern_name in &extern_names {
392391
resolver
393-
.resolve_str_path_error(DUMMY_SP, extern_name, TypeNS, CRATE_NODE_ID)
392+
.resolve_str_path_error(
393+
DUMMY_SP,
394+
extern_name,
395+
TypeNS,
396+
LocalDefId { local_def_index: CRATE_DEF_INDEX },
397+
)
394398
.unwrap_or_else(|()| {
395399
panic!("Unable to resolve external crate {}", extern_name)
396400
});

src/librustdoc/passes/collect_intra_doc_links.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def::{
88
Namespace::{self, *},
99
PerNS, Res,
1010
};
11-
use rustc_hir::def_id::DefId;
11+
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_middle::ty;
1313
use rustc_resolve::ParentScope;
1414
use rustc_session::lint;
@@ -61,7 +61,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
6161
&self,
6262
path_str: &str,
6363
current_item: &Option<String>,
64-
module_id: rustc_ast::ast::NodeId,
64+
module_id: LocalDefId,
6565
) -> Result<(Res, Option<String>), ErrorKind> {
6666
let cx = self.cx;
6767

@@ -137,7 +137,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
137137

138138
// In case we're in a module, try to resolve the relative path.
139139
if let Some(module_id) = parent_id.or(self.mod_ids.last().cloned()) {
140-
let module_id = cx.tcx.hir().hir_id_to_node_id(module_id);
140+
let module_id = cx.tcx.hir().local_def_id(module_id);
141141
let result = cx.enter_resolver(|resolver| {
142142
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
143143
});

0 commit comments

Comments
 (0)