Rollup merge of #70480 - lcnr:appayupyup, r=eddyb
clarify hir_id <-> node_id method names resolves 2 FIXME. r? @eddyb
This commit is contained in:
commit
a023e6121f
@ -241,8 +241,8 @@ fn insert_with_hash(&mut self, span: Span, hir_id: HirId, node: Node<'hir>, hash
|
||||
// Make sure that the DepNode of some node coincides with the HirId
|
||||
// owner of that node.
|
||||
if cfg!(debug_assertions) {
|
||||
let node_id = self.definitions.hir_to_node_id(hir_id);
|
||||
assert_eq!(self.definitions.node_to_hir_id(node_id), hir_id);
|
||||
let node_id = self.definitions.hir_id_to_node_id(hir_id);
|
||||
assert_eq!(self.definitions.node_id_to_hir_id(node_id), hir_id);
|
||||
|
||||
if hir_id.owner != self.current_dep_node_owner {
|
||||
let node_str = match self.definitions.opt_local_def_id(node_id) {
|
||||
@ -342,7 +342,9 @@ fn visit_item(&mut self, i: &'hir Item<'hir>) {
|
||||
debug!("visit_item: {:?}", i);
|
||||
debug_assert_eq!(
|
||||
i.hir_id.owner,
|
||||
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(i.hir_id)).unwrap()
|
||||
self.definitions
|
||||
.opt_local_def_id(self.definitions.hir_id_to_node_id(i.hir_id))
|
||||
.unwrap()
|
||||
);
|
||||
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
|
||||
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
|
||||
@ -374,7 +376,9 @@ fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
|
||||
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
|
||||
debug_assert_eq!(
|
||||
ti.hir_id.owner,
|
||||
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ti.hir_id)).unwrap()
|
||||
self.definitions
|
||||
.opt_local_def_id(self.definitions.hir_id_to_node_id(ti.hir_id))
|
||||
.unwrap()
|
||||
);
|
||||
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
|
||||
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
|
||||
@ -388,7 +392,9 @@ fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
|
||||
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
|
||||
debug_assert_eq!(
|
||||
ii.hir_id.owner,
|
||||
self.definitions.opt_local_def_id(self.definitions.hir_to_node_id(ii.hir_id)).unwrap()
|
||||
self.definitions
|
||||
.opt_local_def_id(self.definitions.hir_id_to_node_id(ii.hir_id))
|
||||
.unwrap()
|
||||
);
|
||||
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
|
||||
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);
|
||||
|
@ -161,7 +161,7 @@ pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
|
||||
#[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_to_hir_id(node);
|
||||
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,
|
||||
@ -184,7 +184,7 @@ pub fn local_def_id(&self, hir_id: HirId) -> DefId {
|
||||
|
||||
#[inline]
|
||||
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
|
||||
let node_id = self.hir_to_node_id(hir_id);
|
||||
let node_id = self.hir_id_to_node_id(hir_id);
|
||||
self.opt_local_def_id_from_node_id(node_id)
|
||||
}
|
||||
|
||||
@ -204,13 +204,13 @@ pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn hir_to_node_id(&self, hir_id: HirId) -> NodeId {
|
||||
self.tcx.definitions.hir_to_node_id(hir_id)
|
||||
pub fn hir_id_to_node_id(&self, hir_id: HirId) -> NodeId {
|
||||
self.tcx.definitions.hir_id_to_node_id(hir_id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn node_to_hir_id(&self, node_id: NodeId) -> HirId {
|
||||
self.tcx.definitions.node_to_hir_id(node_id)
|
||||
pub fn node_id_to_hir_id(&self, node_id: NodeId) -> HirId {
|
||||
self.tcx.definitions.node_id_to_hir_id(node_id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -137,7 +137,7 @@ pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
|
||||
|
||||
#[inline]
|
||||
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
|
||||
self.definitions.node_to_hir_id(node_id)
|
||||
self.definitions.node_id_to_hir_id(node_id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1126,11 +1126,11 @@ pub fn create_global_ctxt(
|
||||
|
||||
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
|
||||
for (k, v) in resolutions.trait_map {
|
||||
let hir_id = definitions.node_to_hir_id(k);
|
||||
let hir_id = definitions.node_id_to_hir_id(k);
|
||||
let map = trait_map.entry(hir_id.owner).or_default();
|
||||
let v = v
|
||||
.into_iter()
|
||||
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
|
||||
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
|
||||
.collect();
|
||||
map.insert(hir_id.local_id, StableVec::new(v));
|
||||
}
|
||||
@ -1154,7 +1154,7 @@ pub fn create_global_ctxt(
|
||||
.map(|(k, v)| {
|
||||
let exports: Vec<_> = v
|
||||
.into_iter()
|
||||
.map(|e| e.map_id(|id| definitions.node_to_hir_id(id)))
|
||||
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
|
||||
.collect();
|
||||
(k, exports)
|
||||
})
|
||||
|
@ -353,15 +353,13 @@ pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(eddyb) rename to `hir_id_to_node_id`.
|
||||
#[inline]
|
||||
pub fn hir_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
|
||||
pub fn hir_id_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
|
||||
self.hir_id_to_node_id[&hir_id]
|
||||
}
|
||||
|
||||
// FIXME(eddyb) rename to `node_id_to_hir_id`.
|
||||
#[inline]
|
||||
pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
|
||||
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
|
||||
self.node_id_to_hir_id[node_id]
|
||||
}
|
||||
|
||||
|
@ -644,7 +644,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
}
|
||||
|
||||
let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect();
|
||||
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
|
||||
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_id_to_node_id(*hir_id));
|
||||
let used_unsafe: FxHashSet<_> =
|
||||
unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect();
|
||||
for &(block_id, is_used) in unsafe_blocks {
|
||||
|
@ -225,7 +225,7 @@ fn process_formals(&mut self, formals: &'l [ast::Param], qualname: &str) {
|
||||
collector.visit_pat(&arg.pat);
|
||||
|
||||
for (id, ident, ..) in collector.collected_idents {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
let typ = match self.save_ctxt.tables.node_type_opt(hir_id) {
|
||||
Some(s) => s.to_string(),
|
||||
None => continue,
|
||||
@ -268,7 +268,7 @@ fn process_method(
|
||||
) {
|
||||
debug!("process_method: {}:{}", id, ident);
|
||||
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
self.nest_tables(id, |v| {
|
||||
if let Some(mut method_data) = v.save_ctxt.get_method_data(id, ident, span) {
|
||||
v.process_formals(&sig.decl.inputs, &method_data.qualname);
|
||||
@ -308,7 +308,7 @@ fn process_method(
|
||||
fn process_struct_field_def(&mut self, field: &ast::StructField, parent_id: NodeId) {
|
||||
let field_data = self.save_ctxt.get_field_data(field, parent_id);
|
||||
if let Some(field_data) = field_data {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(field.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(field.id);
|
||||
self.dumper.dump_def(&access_from!(self.save_ctxt, field, hir_id), field_data);
|
||||
}
|
||||
}
|
||||
@ -360,7 +360,7 @@ fn process_fn(
|
||||
ty_params: &'l ast::Generics,
|
||||
body: Option<&'l ast::Block>,
|
||||
) {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
self.nest_tables(item.id, |v| {
|
||||
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(fn_data, DefData, item.span);
|
||||
@ -402,7 +402,7 @@ fn process_static_or_const_item(
|
||||
typ: &'l ast::Ty,
|
||||
expr: Option<&'l ast::Expr>,
|
||||
) {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
self.nest_tables(item.id, |v| {
|
||||
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(var_data, DefData, item.span);
|
||||
@ -429,7 +429,7 @@ fn process_assoc_const(
|
||||
if !self.span.filter_generated(ident.span) {
|
||||
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
|
||||
let span = self.span_from_span(ident.span);
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access_from_vis!(self.save_ctxt, vis, hir_id),
|
||||
@ -503,7 +503,7 @@ fn process_struct(
|
||||
|
||||
if !self.span.filter_generated(item.ident.span) {
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, hir_id),
|
||||
Def {
|
||||
@ -546,7 +546,7 @@ fn process_enum(
|
||||
};
|
||||
down_cast_data!(enum_data, DefData, item.span);
|
||||
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
let access = access_from!(self.save_ctxt, item, hir_id);
|
||||
|
||||
for variant in &enum_definition.variants {
|
||||
@ -699,7 +699,7 @@ fn process_trait(
|
||||
let id = id_from_node_id(item.id, &self.save_ctxt);
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let children = methods.iter().map(|i| id_from_node_id(i.id, &self.save_ctxt)).collect();
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, hir_id),
|
||||
Def {
|
||||
@ -759,7 +759,7 @@ fn process_trait(
|
||||
fn process_mod(&mut self, item: &ast::Item) {
|
||||
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
|
||||
down_cast_data!(mod_data, DefData, item.span);
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
self.dumper.dump_def(&access_from!(self.save_ctxt, item, hir_id), mod_data);
|
||||
}
|
||||
}
|
||||
@ -864,7 +864,7 @@ fn process_pat(&mut self, p: &'l ast::Pat) {
|
||||
match p.kind {
|
||||
PatKind::Struct(ref _path, ref fields, _) => {
|
||||
// FIXME do something with _path?
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(p.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(p.id);
|
||||
let adt = match self.save_ctxt.tables.node_type_opt(hir_id) {
|
||||
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
|
||||
_ => {
|
||||
@ -903,7 +903,7 @@ fn process_var_decl(&mut self, pat: &'l ast::Pat) {
|
||||
for (id, ident, _) in collector.collected_idents {
|
||||
match self.save_ctxt.get_path_res(id) {
|
||||
Res::Local(hir_id) => {
|
||||
let id = self.tcx.hir().hir_to_node_id(hir_id);
|
||||
let id = self.tcx.hir().hir_id_to_node_id(hir_id);
|
||||
let typ = self
|
||||
.save_ctxt
|
||||
.tables
|
||||
@ -1126,7 +1126,7 @@ fn process_use_tree(
|
||||
|
||||
// The access is calculated using the current tree ID, but with the root tree's visibility
|
||||
// (since nested trees don't have their own visibility).
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
let access = access_from!(self.save_ctxt, root_item, hir_id);
|
||||
|
||||
// The parent `DefId` of a given use tree is always the enclosing item.
|
||||
@ -1321,7 +1321,7 @@ fn visit_item(&mut self, item: &'l ast::Item) {
|
||||
if !self.span.filter_generated(item.ident.span) {
|
||||
let span = self.span_from_span(item.ident.span);
|
||||
let id = id_from_node_id(item.id, &self.save_ctxt);
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access_from!(self.save_ctxt, item, hir_id),
|
||||
@ -1420,7 +1420,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||
self.process_macro_use(ex.span);
|
||||
match ex.kind {
|
||||
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
|
||||
let expr_hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id);
|
||||
let expr_hir_id = self.save_ctxt.tcx.hir().node_id_to_hir_id(ex.id);
|
||||
let hir_expr = self.save_ctxt.tcx.hir().expect_expr(expr_hir_id);
|
||||
let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) {
|
||||
Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(),
|
||||
@ -1429,7 +1429,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id);
|
||||
let node_id = self.save_ctxt.tcx.hir().hir_id_to_node_id(hir_expr.hir_id);
|
||||
let res = self.save_ctxt.get_path_res(node_id);
|
||||
self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
|
||||
}
|
||||
@ -1514,7 +1514,7 @@ fn visit_local(&mut self, l: &'l ast::Local) {
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &'l ast::ForeignItem) {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(item.id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(item.id);
|
||||
let access = access_from!(self.save_ctxt, item, hir_id);
|
||||
|
||||
match item.kind {
|
||||
|
@ -412,7 +412,7 @@ pub fn get_method_data(&self, id: ast::NodeId, ident: ast::Ident, span: Span) ->
|
||||
let trait_id = self.tcx.trait_id_of_impl(impl_id);
|
||||
let mut docs = String::new();
|
||||
let mut attrs = vec![];
|
||||
if let Some(Node::ImplItem(item)) = hir.find(hir.node_to_hir_id(id)) {
|
||||
if let Some(Node::ImplItem(item)) = hir.find(hir.node_id_to_hir_id(id)) {
|
||||
docs = self.docs_for_attrs(&item.attrs);
|
||||
attrs = item.attrs.to_vec();
|
||||
}
|
||||
@ -452,7 +452,7 @@ pub fn get_method_data(&self, id: ast::NodeId, ident: ast::Ident, span: Span) ->
|
||||
Some(def_id) => {
|
||||
let mut docs = String::new();
|
||||
let mut attrs = vec![];
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
|
||||
if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) {
|
||||
docs = self.docs_for_attrs(&item.attrs);
|
||||
@ -511,7 +511,7 @@ pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option<Ref> {
|
||||
}
|
||||
|
||||
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
let expr_hir_id = self.tcx.hir().node_to_hir_id(expr.id);
|
||||
let expr_hir_id = self.tcx.hir().node_id_to_hir_id(expr.id);
|
||||
let hir_node = self.tcx.hir().expect_expr(expr_hir_id);
|
||||
let ty = self.tables.expr_ty_adjusted_opt(&hir_node);
|
||||
if ty.is_none() || ty.unwrap().kind == ty::Error {
|
||||
@ -519,7 +519,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
}
|
||||
match expr.kind {
|
||||
ast::ExprKind::Field(ref sub_ex, ident) => {
|
||||
let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id);
|
||||
let sub_ex_hir_id = self.tcx.hir().node_id_to_hir_id(sub_ex.id);
|
||||
let hir_node = match self.tcx.hir().find(sub_ex_hir_id) {
|
||||
Some(Node::Expr(expr)) => expr,
|
||||
_ => {
|
||||
@ -573,7 +573,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
}
|
||||
}
|
||||
ast::ExprKind::MethodCall(ref seg, ..) => {
|
||||
let expr_hir_id = self.tcx.hir().definitions().node_to_hir_id(expr.id);
|
||||
let expr_hir_id = self.tcx.hir().definitions().node_id_to_hir_id(expr.id);
|
||||
let method_id = match self.tables.type_dependent_def_id(expr_hir_id) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
@ -605,7 +605,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
|
||||
}
|
||||
|
||||
pub fn get_path_res(&self, id: NodeId) -> Res {
|
||||
let hir_id = self.tcx.hir().node_to_hir_id(id);
|
||||
let hir_id = self.tcx.hir().node_id_to_hir_id(id);
|
||||
match self.tcx.hir().get(hir_id) {
|
||||
Node::TraitRef(tr) => tr.path.res,
|
||||
|
||||
@ -619,7 +619,7 @@ pub fn get_path_res(&self, id: NodeId) -> Res {
|
||||
Some(res) if res != Res::Err => res,
|
||||
_ => {
|
||||
let parent_node = self.tcx.hir().get_parent_node(hir_id);
|
||||
self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node))
|
||||
self.get_path_res(self.tcx.hir().hir_id_to_node_id(parent_node))
|
||||
}
|
||||
},
|
||||
|
||||
@ -681,7 +681,7 @@ fn fn_type(seg: &ast::PathSegment) -> bool {
|
||||
Res::Local(id) => Some(Ref {
|
||||
kind: RefKind::Variable,
|
||||
span,
|
||||
ref_id: id_from_node_id(self.tcx.hir().hir_to_node_id(id), self),
|
||||
ref_id: id_from_node_id(self.tcx.hir().hir_id_to_node_id(id), self),
|
||||
}),
|
||||
Res::Def(HirDefKind::Trait, def_id) if fn_type(path_seg) => {
|
||||
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id) })
|
||||
|
@ -135,7 +135,7 @@ fn resolve(
|
||||
|
||||
// In case we're in a module, try to resolve the relative path.
|
||||
if let Some(module_id) = parent_id.or(self.mod_ids.last().cloned()) {
|
||||
let module_id = cx.tcx.hir().hir_to_node_id(module_id);
|
||||
let module_id = cx.tcx.hir().hir_id_to_node_id(module_id);
|
||||
let result = cx.enter_resolver(|resolver| {
|
||||
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user