Skip to content

Commit 4f97338

Browse files
committed
Some changes to save-analysis to cope with errors
1 parent 6bd782c commit 4f97338

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/librustc/middle/ty/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,16 @@ impl<'tcx> ctxt<'tcx> {
19151915
})
19161916
}
19171917

1918+
pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
1919+
self.expr_ty_opt(expr).map(|t| t.adjust(self,
1920+
expr.span,
1921+
expr.id,
1922+
self.tables.borrow().adjustments.get(&expr.id),
1923+
|method_call| {
1924+
self.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
1925+
}))
1926+
}
1927+
19181928
pub fn expr_span(&self, id: NodeId) -> Span {
19191929
match self.map.find(id) {
19201930
Some(ast_map::NodeExpr(e)) => {

src/librustc_trans/save/dump_csv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
801801
"<mutable>".to_string()
802802
};
803803
let types = self.tcx.node_types();
804-
let typ = types.get(&id).unwrap().to_string();
804+
let typ = types.get(&id).map(|t| t.to_string()).unwrap_or(String::new());
805805
// Get the span only for the name of the variable (I hope the path
806806
// is only ever a variable name, but who knows?).
807807
let sub_span = self.span.span_for_last_ident(p.span);

src/librustc_trans/save/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,15 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
463463
}
464464

465465
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
466+
let hir_node = lowering::lower_expr(self.lcx, expr);
467+
let ty = self.tcx.expr_ty_adjusted_opt(&hir_node);
468+
if ty.is_none() || ty.unwrap().sty == ty::TyError {
469+
return None;
470+
}
466471
match expr.node {
467472
ast::ExprField(ref sub_ex, ident) => {
468473
let hir_node = lowering::lower_expr(self.lcx, sub_ex);
469-
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
470-
match *ty {
474+
match self.tcx.expr_ty_adjusted(&hir_node).sty {
471475
ty::TyStruct(def, _) => {
472476
let f = def.struct_variant().field_named(ident.node.name);
473477
let sub_span = self.span_utils.span_for_last_ident(expr.span);
@@ -487,8 +491,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
487491
}
488492
ast::ExprStruct(ref path, _, _) => {
489493
let hir_node = lowering::lower_expr(self.lcx, expr);
490-
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
491-
match *ty {
494+
match self.tcx.expr_ty_adjusted(&hir_node).sty {
492495
ty::TyStruct(def, _) => {
493496
let sub_span = self.span_utils.span_for_last_ident(path.span);
494497
filter!(self.span_utils, sub_span, path.span, None);

0 commit comments

Comments
 (0)