mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
librustc_middle: return LocalDefId instead of DefId in local_def_id_from_node_id
This commit is contained in:
parent
f62c6e1c76
commit
555e024abc
@ -157,19 +157,16 @@ impl<'hir> Map<'hir> {
|
||||
self.tcx.definitions.def_path(def_id)
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this function can and should return `LocalDefId`.
|
||||
#[inline]
|
||||
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
|
||||
self.opt_local_def_id_from_node_id(node)
|
||||
.unwrap_or_else(|| {
|
||||
let hir_id = self.node_id_to_hir_id(node);
|
||||
bug!(
|
||||
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
|
||||
node,
|
||||
self.find_entry(hir_id)
|
||||
)
|
||||
})
|
||||
.to_def_id()
|
||||
pub fn local_def_id_from_node_id(&self, node: NodeId) -> LocalDefId {
|
||||
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
|
||||
let hir_id = self.node_id_to_hir_id(node);
|
||||
bug!(
|
||||
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
|
||||
node,
|
||||
self.find_entry(hir_id)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this function can and should return `LocalDefId`.
|
||||
|
@ -107,7 +107,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id);
|
||||
let item_def_id = self.tcx.hir().local_def_id_from_node_id(item_id).to_def_id();
|
||||
|
||||
let tables = if self.tcx.has_typeck_tables(item_def_id) {
|
||||
self.tcx.typeck_tables_of(item_def_id)
|
||||
@ -423,8 +423,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
vis: ast::Visibility,
|
||||
attrs: &'l [Attribute],
|
||||
) {
|
||||
let qualname =
|
||||
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
|
||||
);
|
||||
|
||||
if !self.span.filter_generated(ident.span) {
|
||||
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
|
||||
@ -470,7 +472,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
|
||||
);
|
||||
|
||||
let kind = match item.kind {
|
||||
@ -670,7 +672,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
}
|
||||
v.process_generic_params(generics, "", item.id);
|
||||
for impl_item in impl_items {
|
||||
v.process_impl_item(impl_item, map.local_def_id_from_node_id(item.id));
|
||||
v.process_impl_item(impl_item, map.local_def_id_from_node_id(item.id).to_def_id());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -685,7 +687,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
|
||||
);
|
||||
let mut val = name.clone();
|
||||
if !generics.params.is_empty() {
|
||||
@ -751,7 +753,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
self.process_generic_params(generics, &qualname, item.id);
|
||||
for method in methods {
|
||||
let map = &self.tcx.hir();
|
||||
self.process_trait_item(method, map.local_def_id_from_node_id(item.id))
|
||||
self.process_trait_item(method, map.local_def_id_from_node_id(item.id).to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
@ -1030,7 +1032,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
let name = trait_item.ident.name.to_string();
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(trait_item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(trait_item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
|
||||
if !self.span.filter_generated(trait_item.ident.span) {
|
||||
@ -1173,7 +1177,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
||||
|
||||
// Make a comma-separated list of names of imported modules.
|
||||
let def_id = self.tcx.hir().local_def_id_from_node_id(id);
|
||||
let names = self.tcx.names_imported_by_glob_use(def_id);
|
||||
let names = self.tcx.names_imported_by_glob_use(def_id.to_def_id());
|
||||
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
|
||||
|
||||
// Otherwise it's a span with wrong macro expansion info, which
|
||||
@ -1227,8 +1231,10 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
|
||||
// only get called for the root module of a crate.
|
||||
assert_eq!(id, ast::CRATE_NODE_ID);
|
||||
|
||||
let qualname =
|
||||
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id)));
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
|
||||
);
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let filename = sm.span_to_filename(span);
|
||||
@ -1311,7 +1317,9 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
|
||||
TyAlias(_, ref ty_params, _, ref ty) => {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
let value = match ty {
|
||||
Some(ty) => ty_to_string(&ty),
|
||||
|
@ -130,7 +130,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id())
|
||||
);
|
||||
match item.kind {
|
||||
ast::ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
|
||||
@ -183,7 +183,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
ast::ItemKind::Fn(_, ref sig, .., ref generics, _) => {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
filter!(self.span_utils, item.ident.span);
|
||||
Some(Data::DefData(Def {
|
||||
@ -204,7 +206,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
ast::ItemKind::Static(ref typ, ..) => {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
|
||||
filter!(self.span_utils, item.ident.span);
|
||||
@ -230,7 +234,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
ast::ItemKind::Const(_, ref typ, _) => {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
filter!(self.span_utils, item.ident.span);
|
||||
|
||||
@ -255,7 +261,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
ast::ItemKind::Mod(ref m) => {
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
@ -282,7 +290,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
let name = item.ident.to_string();
|
||||
let qualname = format!(
|
||||
"::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
|
||||
self.tcx.def_path_str(
|
||||
self.tcx.hir().local_def_id_from_node_id(item.id).to_def_id()
|
||||
)
|
||||
);
|
||||
filter!(self.span_utils, item.ident.span);
|
||||
let variants_str =
|
||||
@ -363,11 +373,11 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
let name = ident.to_string();
|
||||
let qualname = format!(
|
||||
"::{}::{}",
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(scope)),
|
||||
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(scope).to_def_id()),
|
||||
ident
|
||||
);
|
||||
filter!(self.span_utils, ident.span);
|
||||
let def_id = self.tcx.hir().local_def_id_from_node_id(field.id);
|
||||
let def_id = self.tcx.hir().local_def_id_from_node_id(field.id).to_def_id();
|
||||
let typ = self.tcx.type_of(def_id).to_string();
|
||||
|
||||
let id = id_from_node_id(field.id, self);
|
||||
@ -399,7 +409,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
// which the method is declared in, followed by the method's name.
|
||||
let (qualname, parent_scope, decl_id, docs, attributes) = match self
|
||||
.tcx
|
||||
.impl_of_method(self.tcx.hir().local_def_id_from_node_id(id))
|
||||
.impl_of_method(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
|
||||
{
|
||||
Some(impl_id) => match self.tcx.hir().get_if_local(impl_id) {
|
||||
Some(Node::Item(item)) => match item.kind {
|
||||
@ -448,7 +458,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
);
|
||||
}
|
||||
},
|
||||
None => match self.tcx.trait_of_item(self.tcx.hir().local_def_id_from_node_id(id)) {
|
||||
None => match self
|
||||
.tcx
|
||||
.trait_of_item(self.tcx.hir().local_def_id_from_node_id(id).to_def_id())
|
||||
{
|
||||
Some(def_id) => {
|
||||
let mut docs = String::new();
|
||||
let mut attrs = vec![];
|
||||
|
@ -451,7 +451,11 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
|
||||
name: None,
|
||||
attrs: clean::Attributes::default(),
|
||||
source: clean::Span::empty(),
|
||||
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
|
||||
def_id: cx
|
||||
.tcx
|
||||
.hir()
|
||||
.local_def_id_from_node_id(ast::CRATE_NODE_ID)
|
||||
.to_def_id(),
|
||||
visibility: clean::Public,
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
|
@ -1554,7 +1554,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||
BareFunction(box BareFunctionDecl {
|
||||
unsafety: sig.unsafety(),
|
||||
generic_params: Vec::new(),
|
||||
decl: (local_def_id, sig).clean(cx),
|
||||
decl: (local_def_id.to_def_id(), sig).clean(cx),
|
||||
abi: sig.abi(),
|
||||
})
|
||||
}
|
||||
@ -2264,7 +2264,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
|
||||
name: None,
|
||||
attrs: self.attrs.clean(cx),
|
||||
source: self.whence.clean(cx),
|
||||
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID),
|
||||
def_id: cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID).to_def_id(),
|
||||
visibility: self.vis.clean(cx),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
|
Loading…
Reference in New Issue
Block a user