diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2019-04-20 19:36:05 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2019-05-03 22:50:19 +0300 |
| commit | ff174fe09e2e0a8f959b970e6ec410b3aafbc58a (patch) | |
| tree | 87d314d0bb99c7261f64805fbaffed00481be807 /src/librustc_save_analysis | |
| parent | b92b1a76e175f396d7986177d0a2d5907bbba888 (diff) | |
| download | rust-ff174fe09e2e0a8f959b970e6ec410b3aafbc58a.tar.gz rust-ff174fe09e2e0a8f959b970e6ec410b3aafbc58a.zip | |
rustc: rename hir::def::Def to Res (short for "resolution").
Diffstat (limited to 'src/librustc_save_analysis')
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 32 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 94 | ||||
| -rw-r--r-- | src/librustc_save_analysis/sig.rs | 20 |
3 files changed, 73 insertions, 73 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 36413e76a1e..a45e32ddb66 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -13,7 +13,7 @@ //! DumpVisitor walks the AST and processes it, and JsonDumper is used for //! recording the output. -use rustc::hir::def::{Def as HirDef, DefKind as HirDefKind}; +use rustc::hir::def::{Res, DefKind as HirDefKind}; use rustc::hir::def_id::DefId; use rustc::session::config::Input; use rustc::span_bug; @@ -233,8 +233,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { } fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> { - match self.save_ctxt.get_path_def(ref_id) { - HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Err => None, + match self.save_ctxt.get_path_res(ref_id) { + Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } } @@ -884,7 +884,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { return; } }; - let variant = adt.variant_of_def(self.save_ctxt.get_path_def(p.id)); + let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id)); for &Spanned { node: ref field, .. } in fields { if let Some(index) = self.tcx.find_field_index(field.ident, variant) { @@ -914,8 +914,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { // process collected paths for (id, ident, immut) in collector.collected_idents { - match self.save_ctxt.get_path_def(id) { - HirDef::Local(hir_id) => { + match self.save_ctxt.get_path_res(id) { + Res::Local(hir_id) => { let mut value = if immut == ast::Mutability::Immutable { self.span.snippet(ident.span) } else { @@ -957,14 +957,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { ); } } - HirDef::Def(HirDefKind::Ctor(..), _) | - HirDef::Def(HirDefKind::Const, _) | - HirDef::Def(HirDefKind::AssociatedConst, _) | - HirDef::Def(HirDefKind::Struct, _) | - HirDef::Def(HirDefKind::Variant, _) | - HirDef::Def(HirDefKind::TyAlias, _) | - HirDef::Def(HirDefKind::AssociatedTy, _) | - HirDef::SelfTy(..) => { + Res::Def(HirDefKind::Ctor(..), _) | + Res::Def(HirDefKind::Const, _) | + Res::Def(HirDefKind::AssociatedConst, _) | + Res::Def(HirDefKind::Struct, _) | + Res::Def(HirDefKind::Variant, _) | + Res::Def(HirDefKind::TyAlias, _) | + Res::Def(HirDefKind::AssociatedTy, _) | + Res::SelfTy(..) => { self.dump_path_ref(id, &ast::Path::from_ident(ident)); } def => error!( @@ -1538,8 +1538,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc } }; let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id); - let def = self.save_ctxt.get_path_def(node_id); - self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) + let res = self.save_ctxt.get_path_res(node_id); + 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::Field(ref sub_ex, _) => { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 47d0b5055ea..c242b4d6a41 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -15,7 +15,7 @@ mod span_utils; mod sig; use rustc::hir; -use rustc::hir::def::{CtorOf, Def as HirDef, DefKind as HirDefKind}; +use rustc::hir::def::{CtorOf, Res, DefKind as HirDefKind}; use rustc::hir::Node; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::middle::privacy::AccessLevels; @@ -606,21 +606,21 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } } - pub fn get_path_def(&self, id: NodeId) -> HirDef { + pub fn get_path_res(&self, id: NodeId) -> Res { match self.tcx.hir().get(id) { - Node::TraitRef(tr) => tr.path.def, + Node::TraitRef(tr) => tr.path.res, Node::Item(&hir::Item { node: hir::ItemKind::Use(ref path, _), .. }) | Node::Visibility(&Spanned { - node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.def, + node: hir::VisibilityKind::Restricted { ref path, .. }, .. }) => path.res, Node::PathSegment(seg) => { - match seg.def { - Some(def) if def != HirDef::Err => def, - _ => self.get_path_def(self.tcx.hir().get_parent_node(id)), + match seg.res { + Some(res) if res != Res::Err => res, + _ => self.get_path_res(self.tcx.hir().get_parent_node(id)), } } @@ -629,7 +629,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { .. }) => { let hir_id = self.tcx.hir().node_to_hir_id(id); - self.tables.qpath_def(qpath, hir_id) + self.tables.qpath_res(qpath, hir_id) } Node::Expr(&hir::Expr { @@ -653,15 +653,15 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { .. }) => { let hir_id = self.tcx.hir().node_to_hir_id(id); - self.tables.qpath_def(qpath, hir_id) + self.tables.qpath_res(qpath, hir_id) } Node::Binding(&hir::Pat { node: hir::PatKind::Binding(_, canonical_id, ..), .. - }) => HirDef::Local(canonical_id), + }) => Res::Local(canonical_id), - _ => HirDef::Err, + _ => Res::Err, } } @@ -697,52 +697,52 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { return None; } - let def = self.get_path_def(id); + let res = self.get_path_res(id); let span = path_seg.ident.span; filter!(self.span_utils, span); let span = self.span_from_span(span); - match def { - HirDef::Upvar(id, ..) | HirDef::Local(id) => { + match res { + Res::Upvar(id, ..) | Res::Local(id) => { Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_node_id(self.tcx.hir().hir_to_node_id(id), self), }) } - HirDef::Def(HirDefKind::Trait, def_id) if fn_type(path_seg) => { + 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), }) } - HirDef::Def(HirDefKind::Struct, def_id) | - HirDef::Def(HirDefKind::Variant, def_id) | - HirDef::Def(HirDefKind::Union, def_id) | - HirDef::Def(HirDefKind::Enum, def_id) | - HirDef::Def(HirDefKind::TyAlias, def_id) | - HirDef::Def(HirDefKind::ForeignTy, def_id) | - HirDef::Def(HirDefKind::TraitAlias, def_id) | - HirDef::Def(HirDefKind::AssociatedExistential, def_id) | - HirDef::Def(HirDefKind::AssociatedTy, def_id) | - HirDef::Def(HirDefKind::Trait, def_id) | - HirDef::Def(HirDefKind::Existential, def_id) | - HirDef::Def(HirDefKind::TyParam, def_id) => { + Res::Def(HirDefKind::Struct, def_id) | + Res::Def(HirDefKind::Variant, def_id) | + Res::Def(HirDefKind::Union, def_id) | + Res::Def(HirDefKind::Enum, def_id) | + Res::Def(HirDefKind::TyAlias, def_id) | + Res::Def(HirDefKind::ForeignTy, def_id) | + Res::Def(HirDefKind::TraitAlias, def_id) | + Res::Def(HirDefKind::AssociatedExistential, def_id) | + Res::Def(HirDefKind::AssociatedTy, def_id) | + Res::Def(HirDefKind::Trait, def_id) | + Res::Def(HirDefKind::Existential, def_id) | + Res::Def(HirDefKind::TyParam, def_id) => { Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(def_id), }) } - HirDef::Def(HirDefKind::ConstParam, def_id) => { + Res::Def(HirDefKind::ConstParam, def_id) => { Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id), }) } - HirDef::Def(HirDefKind::Ctor(CtorOf::Struct, ..), def_id) => { + Res::Def(HirDefKind::Ctor(CtorOf::Struct, ..), def_id) => { // This is a reference to a tuple struct where the def_id points // to an invisible constructor function. That is not a very useful // def, so adjust to point to the tuple struct itself. @@ -753,17 +753,17 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(parent_def_id), }) } - HirDef::Def(HirDefKind::Static, _) | - HirDef::Def(HirDefKind::Const, _) | - HirDef::Def(HirDefKind::AssociatedConst, _) | - HirDef::Def(HirDefKind::Ctor(..), _) => { + Res::Def(HirDefKind::Static, _) | + Res::Def(HirDefKind::Const, _) | + Res::Def(HirDefKind::AssociatedConst, _) | + Res::Def(HirDefKind::Ctor(..), _) => { Some(Ref { kind: RefKind::Variable, span, - ref_id: id_from_def_id(def.def_id()), + ref_id: id_from_def_id(res.def_id()), }) } - HirDef::Def(HirDefKind::Method, decl_id) => { + Res::Def(HirDefKind::Method, decl_id) => { let def_id = if decl_id.is_local() { let ti = self.tcx.associated_item(decl_id); self.tcx @@ -780,28 +780,28 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(def_id.unwrap_or(decl_id)), }) } - HirDef::Def(HirDefKind::Fn, def_id) => { + Res::Def(HirDefKind::Fn, def_id) => { Some(Ref { kind: RefKind::Function, span, ref_id: id_from_def_id(def_id), }) } - HirDef::Def(HirDefKind::Mod, def_id) => { + Res::Def(HirDefKind::Mod, def_id) => { Some(Ref { kind: RefKind::Mod, span, ref_id: id_from_def_id(def_id), }) } - HirDef::PrimTy(..) | - HirDef::SelfTy(..) | - HirDef::Label(..) | - HirDef::Def(HirDefKind::Macro(..), _) | - HirDef::ToolMod | - HirDef::NonMacroAttr(..) | - HirDef::SelfCtor(..) | - HirDef::Err => None, + Res::PrimTy(..) | + Res::SelfTy(..) | + Res::Label(..) | + Res::Def(HirDefKind::Macro(..), _) | + Res::ToolMod | + Res::NonMacroAttr(..) | + Res::SelfCtor(..) | + Res::Err => None, } } @@ -870,8 +870,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> { - match self.get_path_def(ref_id) { - HirDef::PrimTy(_) | HirDef::SelfTy(..) | HirDef::Err => None, + match self.get_path_res(ref_id) { + Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index bcdb6be0ebd..4f759b8a73f 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -29,7 +29,7 @@ use crate::{id_from_def_id, id_from_node_id, SaveContext}; use rls_data::{SigElement, Signature}; -use rustc::hir::def::{Def, DefKind}; +use rustc::hir::def::{Res, DefKind}; use syntax::ast::{self, NodeId}; use syntax::print::pprust; @@ -273,8 +273,8 @@ impl Sig for ast::Ty { }; let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?); - let def = scx.get_path_def(id.ok_or("Missing id for Path")?); - let id = id_from_def_id(def.def_id()); + let res = scx.get_path_res(id.ok_or("Missing id for Path")?); + let id = id_from_def_id(res.def_id()); if path.segments.len() - qself.position == 1 { let start = offset + prefix.len(); let end = start + name.len(); @@ -576,19 +576,19 @@ impl Sig for ast::Item { impl Sig for ast::Path { fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result { - let def = scx.get_path_def(id.ok_or("Missing id for Path")?); + let res = scx.get_path_res(id.ok_or("Missing id for Path")?); - let (name, start, end) = match def { - Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => { + let (name, start, end) = match res { + Res::Label(..) | Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => { return Ok(Signature { text: pprust::path_to_string(self), defs: vec![], refs: vec![], }) } - Def::Def(DefKind::AssociatedConst, _) - | Def::Def(DefKind::Variant, _) - | Def::Def(DefKind::Ctor(..), _) => { + Res::Def(DefKind::AssociatedConst, _) + | Res::Def(DefKind::Variant, _) + | Res::Def(DefKind::Ctor(..), _) => { let len = self.segments.len(); if len < 2 { return Err("Bad path"); @@ -608,7 +608,7 @@ impl Sig for ast::Path { } }; - let id = id_from_def_id(def.def_id()); + let id = id_from_def_id(res.def_id()); Ok(Signature { text: name, defs: vec![], |
