Skip to content

Commit c8ee3f2

Browse files
committed
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.
1 parent dd6e8d4 commit c8ee3f2

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;
@@ -392,7 +392,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
392392
}
393393
match expr.node {
394394
ast::ExprKind::Field(ref sub_ex, ident) => {
395-
let hir_node = self.tcx.map.expect_expr(sub_ex.id);
395+
let hir_node = match self.tcx.map.find(sub_ex.id) {
396+
Some(Node::NodeExpr(expr)) => expr,
397+
_ => {
398+
debug!("Missing or weird node for sub-expression {} in {:?}",
399+
sub_ex.id, expr);
400+
return None;
401+
}
402+
};
396403
match self.tcx.expr_ty_adjusted(&hir_node).sty {
397404
ty::TyStruct(def, _) => {
398405
let f = def.struct_variant().field_named(ident.node.name);
@@ -412,7 +419,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
412419
}
413420
}
414421
ast::ExprKind::Struct(ref path, _, _) => {
415-
let hir_node = self.tcx.map.expect_expr(expr.id);
416422
match self.tcx.expr_ty_adjusted(&hir_node).sty {
417423
ty::TyStruct(def, _) => {
418424
let sub_span = self.span_utils.span_for_last_ident(path.span);

0 commit comments

Comments
 (0)