]> git.lizzy.rs Git - rust.git/commitdiff
Some changes to save-analysis to cope with errors
authorNick Cameron <ncameron@mozilla.com>
Thu, 28 Jan 2016 00:10:04 +0000 (13:10 +1300)
committerNick Cameron <ncameron@mozilla.com>
Sun, 31 Jan 2016 19:42:27 +0000 (08:42 +1300)
src/librustc/middle/ty/mod.rs
src/librustc_trans/save/dump_csv.rs
src/librustc_trans/save/mod.rs

index 06ea945a09eb3c0b055e179928127de29a688a8a..3a57474c30322435157d69761469714f2a9ad316 100644 (file)
@@ -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<Ty<'tcx>> {
+        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)) => {
index 2951cf2ee1ba4d28a66579b58ea6ab07ed00b5cb..21d536667e5a0425f10283e925ededf4eca3fecc 100644 (file)
@@ -801,7 +801,7 @@ fn process_var_decl(&mut self, p: &ast::Pat, value: String) {
                 "<mutable>".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);
index 37b23d6ee9ce9a9b74dce531d3694fd92da20542..05b012d55a07e85586263e196264df454f46e42e 100644 (file)
@@ -463,11 +463,15 @@ pub fn get_trait_ref_data(&self,
     }
 
     pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
+        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<Data> {
             }
             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);