revert the NodeId to HirId parameter change to get_path_res

This commit is contained in:
ljedrz 2019-06-21 08:57:34 +02:00
parent 73cb9ab526
commit 0a511cce79
3 changed files with 12 additions and 17 deletions

View File

@ -233,8 +233,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
} }
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> { fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ref_id); match self.save_ctxt.get_path_res(ref_id) {
match self.save_ctxt.get_path_res(hir_id) {
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None, Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
def => Some(def.def_id()), def => Some(def.def_id()),
} }
@ -887,8 +886,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
return; return;
} }
}; };
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(p.id); let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(hir_id));
for &Spanned { node: ref field, .. } in fields { for &Spanned { node: ref field, .. } in fields {
if let Some(index) = self.tcx.find_field_index(field.ident, variant) { if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
@ -918,8 +916,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
// process collected paths // process collected paths
for (id, ident, immut) in collector.collected_idents { for (id, ident, immut) in collector.collected_idents {
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(id); match self.save_ctxt.get_path_res(id) {
match self.save_ctxt.get_path_res(hir_id) {
Res::Local(hir_id) => { Res::Local(hir_id) => {
let mut value = if immut == ast::Mutability::Immutable { let mut value = if immut == ast::Mutability::Immutable {
self.span.snippet(ident.span) self.span.snippet(ident.span)
@ -1543,7 +1540,8 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, '
return; return;
} }
}; };
let res = self.save_ctxt.get_path_res(hir_expr.hir_id); let node_id = self.save_ctxt.tcx.hir().hir_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) self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
} }
ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args), ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args),

View File

@ -606,7 +606,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
} }
} }
pub fn get_path_res(&self, hir_id: hir::HirId) -> Res { pub fn get_path_res(&self, id: NodeId) -> Res {
let hir_id = self.tcx.hir().node_to_hir_id(id);
match self.tcx.hir().get(hir_id) { match self.tcx.hir().get(hir_id) {
Node::TraitRef(tr) => tr.path.res, Node::TraitRef(tr) => tr.path.res,
@ -620,7 +621,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
Node::PathSegment(seg) => { Node::PathSegment(seg) => {
match seg.res { match seg.res {
Some(res) if res != Res::Err => res, Some(res) if res != Res::Err => res,
_ => self.get_path_res(self.tcx.hir().get_parent_node_by_hir_id(hir_id)), _ => self.get_path_res(self.tcx.hir().get_parent_node(id)),
} }
} }
@ -695,8 +696,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
return None; return None;
} }
let hir_id = self.tcx.hir().node_to_hir_id(id); let res = self.get_path_res(id);
let res = self.get_path_res(hir_id);
let span = path_seg.ident.span; let span = path_seg.ident.span;
filter!(self.span_utils, span); filter!(self.span_utils, span);
let span = self.span_from_span(span); let span = self.span_from_span(span);
@ -868,8 +868,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
} }
fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> { fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> {
let hir_id = self.tcx.hir().node_to_hir_id(ref_id); match self.get_path_res(ref_id) {
match self.get_path_res(hir_id) {
Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None, Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
def => Some(def.def_id()), def => Some(def.def_id()),
} }

View File

@ -273,8 +273,7 @@ impl Sig for ast::Ty {
}; };
let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?); let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?);
let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
let id = id_from_def_id(res.def_id()); let id = id_from_def_id(res.def_id());
if path.segments.len() - qself.position == 1 { if path.segments.len() - qself.position == 1 {
let start = offset + prefix.len(); let start = offset + prefix.len();
@ -577,8 +576,7 @@ impl Sig for ast::Item {
impl Sig for ast::Path { impl Sig for ast::Path {
fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result { fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result {
let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
let (name, start, end) = match res { let (name, start, end) = match res {
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => { Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => {