Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save-analysis: be a bit more defensive with field sub-expressions #33859

Merged
merged 1 commit into from
May 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod external_data;
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;
Expand Down Expand Up @@ -392,7 +392,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
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);
Expand All @@ -412,7 +419,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
}
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);
Expand Down