]> git.lizzy.rs Git - rust.git/commitdiff
save-analysis: be a bit more defensive with field sub-expressions
authorNick Cameron <ncameron@mozilla.com>
Wed, 25 May 2016 03:24:55 +0000 (15:24 +1200)
committerNick Cameron <ncameron@mozilla.com>
Wed, 25 May 2016 03:24:55 +0000 (15:24 +1200)
Prevents an ice with `(...).f` since the sub-expression is in the AST but not the HIR.

We could actually do better in this specific case, but it doesn't seem worth it.

src/librustc_save_analysis/lib.rs

index 8c00a5699939824f2f1882c94d1ef66ada74d37b..8c3c65466427c5945ba9d56272d6aa4029f31300 100644 (file)
@@ -38,7 +38,7 @@
 pub mod span_utils;
 
 use rustc::hir;
-use rustc::hir::map::NodeItem;
+use rustc::hir::map::{Node, NodeItem};
 use rustc::hir::def::Def;
 use rustc::hir::def_id::DefId;
 use rustc::session::config::CrateType::CrateTypeExecutable;
@@ -392,7 +392,14 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
         }
         match expr.node {
             ast::ExprKind::Field(ref sub_ex, ident) => {
-                let hir_node = self.tcx.map.expect_expr(sub_ex.id);
+                let hir_node = match self.tcx.map.find(sub_ex.id) {
+                    Some(Node::NodeExpr(expr)) => expr,
+                    _ => {
+                        debug!("Missing or weird node for sub-expression {} in {:?}",
+                               sub_ex.id, expr);
+                        return None;
+                    }
+                };
                 match self.tcx.expr_ty_adjusted(&hir_node).sty {
                     ty::TyStruct(def, _) => {
                         let f = def.struct_variant().field_named(ident.node.name);
@@ -412,7 +419,6 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
                 }
             }
             ast::ExprKind::Struct(ref path, _, _) => {
-                let hir_node = self.tcx.map.expect_expr(expr.id);
                 match self.tcx.expr_ty_adjusted(&hir_node).sty {
                     ty::TyStruct(def, _) => {
                         let sub_span = self.span_utils.span_for_last_ident(path.span);