Skip to content

Commit a2a8694

Browse files
committed
Auto merge of #33859 - nrc:save-field-sub, r=pnkfelix
save-analysis: be a bit more defensive with field sub-expressions 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.
2 parents 8f3e8c7 + c8ee3f2 commit a2a8694

File tree

1 file changed

+9
-3
lines changed
  • src/librustc_save_analysis

1 file changed

+9
-3
lines changed

src/librustc_save_analysis/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub mod external_data;
3838
pub mod span_utils;
3939

4040
use rustc::hir;
41-
use rustc::hir::map::NodeItem;
41+
use rustc::hir::map::{Node, NodeItem};
4242
use rustc::hir::def::Def;
4343
use rustc::hir::def_id::DefId;
4444
use rustc::session::config::CrateType::CrateTypeExecutable;
@@ -391,7 +391,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
391391
}
392392
match expr.node {
393393
ast::ExprKind::Field(ref sub_ex, ident) => {
394-
let hir_node = self.tcx.map.expect_expr(sub_ex.id);
394+
let hir_node = match self.tcx.map.find(sub_ex.id) {
395+
Some(Node::NodeExpr(expr)) => expr,
396+
_ => {
397+
debug!("Missing or weird node for sub-expression {} in {:?}",
398+
sub_ex.id, expr);
399+
return None;
400+
}
401+
};
395402
match self.tcx.expr_ty_adjusted(&hir_node).sty {
396403
ty::TyStruct(def, _) => {
397404
let f = def.struct_variant().field_named(ident.node.name);
@@ -411,7 +418,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
411418
}
412419
}
413420
ast::ExprKind::Struct(ref path, _, _) => {
414-
let hir_node = self.tcx.map.expect_expr(expr.id);
415421
match self.tcx.expr_ty_adjusted(&hir_node).sty {
416422
ty::TyStruct(def, _) => {
417423
let sub_span = self.span_utils.span_for_last_ident(path.span);

0 commit comments

Comments
 (0)