diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-06-03 23:15:00 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-06-10 01:03:54 +0300 |
| commit | ee4e55398b39509bde4cc4983d615dbde406355c (patch) | |
| tree | 1b5f331cb8fd834678574e19a5b0dc9308b7fd85 /src/librustc_save_analysis | |
| parent | 4c30f6405c80fe2cd5f1789838ded06020a50457 (diff) | |
| download | rust-ee4e55398b39509bde4cc4983d615dbde406355c.tar.gz rust-ee4e55398b39509bde4cc4983d615dbde406355c.zip | |
Introduce TyCtxt::expect_def/expect_resolution helpers and use them where possible
Diffstat (limited to 'src/librustc_save_analysis')
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 36 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 14 |
2 files changed, 12 insertions, 38 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 4d79ddfe8cb..216d188a503 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -269,14 +269,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { // looks up anything, not just a type fn lookup_type_ref(&self, ref_id: NodeId) -> Option<DefId> { - if !self.tcx.def_map.borrow().contains_key(&ref_id) { - bug!("def_map has no key for {} in lookup_type_ref", ref_id); - } - let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def(); - match def { + match self.tcx.expect_def(ref_id) { Def::PrimTy(..) => None, Def::SelfTy(..) => None, - _ => Some(def.def_id()), + def => Some(def.def_id()), } } @@ -290,13 +286,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { return; } - let def_map = self.tcx.def_map.borrow(); - if !def_map.contains_key(&ref_id) { - span_bug!(span, - "def_map has no key for {} in lookup_def_kind", - ref_id); - } - let def = def_map.get(&ref_id).unwrap().full_def(); + let def = self.tcx.expect_def(ref_id); match def { Def::Mod(_) | Def::ForeignMod(_) => { @@ -853,9 +843,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } // Modules or types in the path prefix. - let def_map = self.tcx.def_map.borrow(); - let def = def_map.get(&id).unwrap().full_def(); - match def { + match self.tcx.expect_def(id) { Def::Method(did) => { let ti = self.tcx.impl_or_trait_item(did); if let ty::MethodTraitItem(m) = ti { @@ -924,8 +912,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { PatKind::Struct(ref path, ref fields, _) => { visit::walk_path(self, path); let adt = self.tcx.node_id_to_type(p.id).ty_adt_def().unwrap(); - let def = self.tcx.def_map.borrow()[&p.id].full_def(); - let variant = adt.variant_of_def(def); + let variant = adt.variant_of_def(self.tcx.expect_def(p.id)); for &Spanned { node: ref field, span } in fields { let sub_span = self.span.span_for_first_ident(span); @@ -1269,7 +1256,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx, ast::ExprKind::Struct(ref path, ref fields, ref base) => { let hir_expr = self.save_ctxt.tcx.map.expect_expr(ex.id); let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap(); - let def = self.tcx.resolve_expr(&hir_expr); + let def = self.tcx.expect_def(hir_expr.id); self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) } ast::ExprKind::MethodCall(_, _, ref args) => self.process_method_call(ex, args), @@ -1366,12 +1353,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx, // process collected paths for &(id, ref p, immut, ref_kind) in &collector.collected_paths { - let def_map = self.tcx.def_map.borrow(); - if !def_map.contains_key(&id) { - span_bug!(p.span, "def_map has no key for {} in visit_arm", id); - } - let def = def_map.get(&id).unwrap().full_def(); - match def { + match self.tcx.expect_def(id) { Def::Local(_, id) => { let value = if immut == ast::Mutability::Immutable { self.span.snippet(p.span).to_string() @@ -1401,8 +1383,8 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx, Def::Static(_, _) | Def::Const(..) | Def::AssociatedConst(..) => {} - _ => error!("unexpected definition kind when processing collected paths: {:?}", - def), + def => error!("unexpected definition kind when processing collected paths: {:?}", + def), } } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 23c03670c1e..27f15756a91 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -465,11 +465,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> { - let def_map = self.tcx.def_map.borrow(); - if !def_map.contains_key(&id) { - span_bug!(path.span, "def_map has no key for {} in visit_expr", id); - } - let def = def_map.get(&id).unwrap().full_def(); + let def = self.tcx.expect_def(id); let sub_span = self.span_utils.span_for_last_ident(path.span); filter!(self.span_utils, sub_span, path.span, None); match def { @@ -637,13 +633,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> { - if !self.tcx.def_map.borrow().contains_key(&ref_id) { - bug!("def_map has no key for {} in lookup_type_ref", ref_id); - } - let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def(); - match def { + match self.tcx.expect_def(ref_id) { Def::PrimTy(_) | Def::SelfTy(..) => None, - _ => Some(def.def_id()), + def => Some(def.def_id()), } } |
