From: Nick Cameron Date: Thu, 28 Jan 2016 00:10:04 +0000 (+1300) Subject: Some changes to save-analysis to cope with errors X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=4f97338a3aec3f05e2f2b148ff79903875ea2a9f;p=rust.git Some changes to save-analysis to cope with errors --- diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index 06ea945a09e..3a57474c303 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -1915,6 +1915,16 @@ pub fn expr_ty_adjusted(&self, expr: &hir::Expr) -> Ty<'tcx> { }) } + pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option> { + self.expr_ty_opt(expr).map(|t| t.adjust(self, + expr.span, + expr.id, + self.tables.borrow().adjustments.get(&expr.id), + |method_call| { + self.tables.borrow().method_map.get(&method_call).map(|method| method.ty) + })) + } + pub fn expr_span(&self, id: NodeId) -> Span { match self.map.find(id) { Some(ast_map::NodeExpr(e)) => { diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 2951cf2ee1b..21d536667e5 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -801,7 +801,7 @@ fn process_var_decl(&mut self, p: &ast::Pat, value: String) { "".to_string() }; let types = self.tcx.node_types(); - let typ = types.get(&id).unwrap().to_string(); + let typ = types.get(&id).map(|t| t.to_string()).unwrap_or(String::new()); // Get the span only for the name of the variable (I hope the path // is only ever a variable name, but who knows?). let sub_span = self.span.span_for_last_ident(p.span); diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 37b23d6ee9c..05b012d55a0 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -463,11 +463,15 @@ pub fn get_trait_ref_data(&self, } pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { + let hir_node = lowering::lower_expr(self.lcx, expr); + let ty = self.tcx.expr_ty_adjusted_opt(&hir_node); + if ty.is_none() || ty.unwrap().sty == ty::TyError { + return None; + } match expr.node { ast::ExprField(ref sub_ex, ident) => { let hir_node = lowering::lower_expr(self.lcx, sub_ex); - let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty; - match *ty { + match self.tcx.expr_ty_adjusted(&hir_node).sty { ty::TyStruct(def, _) => { let f = def.struct_variant().field_named(ident.node.name); let sub_span = self.span_utils.span_for_last_ident(expr.span); @@ -487,8 +491,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { } ast::ExprStruct(ref path, _, _) => { let hir_node = lowering::lower_expr(self.lcx, expr); - let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty; - match *ty { + match self.tcx.expr_ty_adjusted(&hir_node).sty { ty::TyStruct(def, _) => { let sub_span = self.span_utils.span_for_last_ident(path.span); filter!(self.span_utils, sub_span, path.span, None);