Skip to content

Commit 555e024

Browse files
committed
librustc_middle: return LocalDefId instead of DefId in local_def_id_from_node_id
1 parent f62c6e1 commit 555e024

File tree

5 files changed

+59
-37
lines changed

5 files changed

+59
-37
lines changed

src/librustc_middle/hir/map/mod.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,16 @@ impl<'hir> Map<'hir> {
157157
self.tcx.definitions.def_path(def_id)
158158
}
159159

160-
// FIXME(eddyb) this function can and should return `LocalDefId`.
161160
#[inline]
162-
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
163-
self.opt_local_def_id_from_node_id(node)
164-
.unwrap_or_else(|| {
165-
let hir_id = self.node_id_to_hir_id(node);
166-
bug!(
167-
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
168-
node,
169-
self.find_entry(hir_id)
170-
)
171-
})
172-
.to_def_id()
161+
pub fn local_def_id_from_node_id(&self, node: NodeId) -> LocalDefId {
162+
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
163+
let hir_id = self.node_id_to_hir_id(node);
164+
bug!(
165+
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
166+
node,
167+
self.find_entry(hir_id)
168+
)
169+
})
173170
}
174171

175172
// FIXME(eddyb) this function can and should return `LocalDefId`.

src/librustc_save_analysis/dump_visitor.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
107107
where
108108
F: FnOnce(&mut Self),
109109
{
110-
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
110+
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id).to_def_id();
111111

112112
let tables = if self.tcx.has_typeck_tables(item_def_id) {
113113
self.tcx.typeck_tables_of(item_def_id)
@@ -423,8 +423,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
423423
vis: ast::Visibility,
424424
attrs: &'l [Attribute],
425425
) {
426-
let qualname =
427-
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
426+
let qualname = format!(
427+
"::{}",
428+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
429+
);
428430

429431
if !self.span.filter_generated(ident.span) {
430432
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
@@ -470,7 +472,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
470472
let name = item.ident.to_string();
471473
let qualname = format!(
472474
"::{}",
473-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
475+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
474476
);
475477

476478
let kind = match item.kind {
@@ -670,7 +672,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
670672
}
671673
v.process_generic_params(generics, "", item.id);
672674
for impl_item in impl_items {
673-
v.process_impl_item(impl_item, map.local_def_id_from_node_id(item.id));
675+
v.process_impl_item(impl_item, map.local_def_id_from_node_id(item.id).to_def_id());
674676
}
675677
});
676678
}
@@ -685,7 +687,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
685687
let name = item.ident.to_string();
686688
let qualname = format!(
687689
"::{}",
688-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
690+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
689691
);
690692
let mut val = name.clone();
691693
if !generics.params.is_empty() {
@@ -751,7 +753,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
751753
self.process_generic_params(generics, &qualname, item.id);
752754
for method in methods {
753755
let map = &self.tcx.hir();
754-
self.process_trait_item(method, map.local_def_id_from_node_id(item.id))
756+
self.process_trait_item(method, map.local_def_id_from_node_id(item.id).to_def_id())
755757
}
756758
}
757759

@@ -1030,7 +1032,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
10301032
let name = trait_item.ident.name.to_string();
10311033
let qualname = format!(
10321034
"::{}",
1033-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(trait_item.id))
1035+
self.tcx.def_path_str(
1036+
self.tcx.hir().local_def_id_from_node_id(trait_item.id).to_def_id()
1037+
)
10341038
);
10351039

10361040
if !self.span.filter_generated(trait_item.ident.span) {
@@ -1173,7 +1177,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11731177

11741178
// Make a comma-separated list of names of imported modules.
11751179
let def_id = self.tcx.hir().local_def_id_from_node_id(id);
1176-
let names = self.tcx.names_imported_by_glob_use(def_id);
1180+
let names = self.tcx.names_imported_by_glob_use(def_id.to_def_id());
11771181
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
11781182

11791183
// Otherwise it's a span with wrong macro expansion info, which
@@ -1227,8 +1231,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
12271231
// only get called for the root module of a crate.
12281232
assert_eq!(id, ast::CRATE_NODE_ID);
12291233

1230-
let qualname =
1231-
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
1234+
let qualname = format!(
1235+
"::{}",
1236+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
1237+
);
12321238

12331239
let sm = self.tcx.sess.source_map();
12341240
let filename = sm.span_to_filename(span);
@@ -1311,7 +1317,9 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
13111317
TyAlias(_, ref ty_params, _, ref ty) => {
13121318
let qualname = format!(
13131319
"::{}",
1314-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
1320+
self.tcx.def_path_str(
1321+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
1322+
)
13151323
);
13161324
let value = match ty {
13171325
Some(ty) => ty_to_string(&ty),

src/librustc_save_analysis/lib.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
130130
pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
131131
let qualname = format!(
132132
"::{}",
133-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
133+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
134134
);
135135
match item.kind {
136136
ast::ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
@@ -183,7 +183,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
183183
ast::ItemKind::Fn(_, ref sig, .., ref generics, _) => {
184184
let qualname = format!(
185185
"::{}",
186-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
186+
self.tcx.def_path_str(
187+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
188+
)
187189
);
188190
filter!(self.span_utils, item.ident.span);
189191
Some(Data::DefData(Def {
@@ -204,7 +206,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
204206
ast::ItemKind::Static(ref typ, ..) => {
205207
let qualname = format!(
206208
"::{}",
207-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
209+
self.tcx.def_path_str(
210+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
211+
)
208212
);
209213

210214
filter!(self.span_utils, item.ident.span);
@@ -230,7 +234,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
230234
ast::ItemKind::Const(_, ref typ, _) => {
231235
let qualname = format!(
232236
"::{}",
233-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
237+
self.tcx.def_path_str(
238+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
239+
)
234240
);
235241
filter!(self.span_utils, item.ident.span);
236242

@@ -255,7 +261,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
255261
ast::ItemKind::Mod(ref m) => {
256262
let qualname = format!(
257263
"::{}",
258-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
264+
self.tcx.def_path_str(
265+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
266+
)
259267
);
260268

261269
let sm = self.tcx.sess.source_map();
@@ -282,7 +290,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
282290
let name = item.ident.to_string();
283291
let qualname = format!(
284292
"::{}",
285-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
293+
self.tcx.def_path_str(
294+
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
295+
)
286296
);
287297
filter!(self.span_utils, item.ident.span);
288298
let variants_str =
@@ -363,11 +373,11 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
363373
let name = ident.to_string();
364374
let qualname = format!(
365375
"::{}::{}",
366-
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(scope)),
376+
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(scope).to_def_id()),
367377
ident
368378
);
369379
filter!(self.span_utils, ident.span);
370-
let def_id = self.tcx.hir().local_def_id_from_node_id(field.id);
380+
let def_id = self.tcx.hir().local_def_id_from_node_id(field.id).to_def_id();
371381
let typ = self.tcx.type_of(def_id).to_string();
372382

373383
let id = id_from_node_id(field.id, self);
@@ -399,7 +409,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
399409
// which the method is declared in, followed by the method's name.
400410
let (qualname, parent_scope, decl_id, docs, attributes) = match self
401411
.tcx
402-
.impl_of_method(self.tcx.hir().local_def_id_from_node_id(id))
412+
.impl_of_method(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
403413
{
404414
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
405415
Some(Node::Item(item)) => match item.kind {
@@ -448,7 +458,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
448458
);
449459
}
450460
},
451-
None => match self.tcx.trait_of_item(self.tcx.hir().local_def_id_from_node_id(id)) {
461+
None => match self
462+
.tcx
463+
.trait_of_item(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
464+
{
452465
Some(def_id) => {
453466
let mut docs = String::new();
454467
let mut attrs = vec![];

src/librustdoc/clean/inline.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,11 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
451451
name: None,
452452
attrs: clean::Attributes::default(),
453453
source: clean::Span::empty(),
454-
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
454+
def_id: cx
455+
.tcx
456+
.hir()
457+
.local_def_id_from_node_id(ast::CRATE_NODE_ID)
458+
.to_def_id(),
455459
visibility: clean::Public,
456460
stability: None,
457461
deprecation: None,

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
15541554
BareFunction(box BareFunctionDecl {
15551555
unsafety: sig.unsafety(),
15561556
generic_params: Vec::new(),
1557-
decl: (local_def_id, sig).clean(cx),
1557+
decl: (local_def_id.to_def_id(), sig).clean(cx),
15581558
abi: sig.abi(),
15591559
})
15601560
}
@@ -2264,7 +2264,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22642264
name: None,
22652265
attrs: self.attrs.clean(cx),
22662266
source: self.whence.clean(cx),
2267-
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
2267+
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID).to_def_id(),
22682268
visibility: self.vis.clean(cx),
22692269
stability: None,
22702270
deprecation: None,

0 commit comments

Comments
 (0)