Skip to content

Commit

Permalink
Some changes to save-analysis to cope with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Jan 31, 2016
1 parent 6bd782c commit 4f97338
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,16 @@ impl<'tcx> ctxt<'tcx> {
})
}

pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> {
self.expr_ty_opt(expr).map(|t| t.adjust(self,
expr.span,
expr.id,
self.tables.borrow().adjustments.get(&expr.id),
|method_call| {
self.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
}))
}

pub fn expr_span(&self, id: NodeId) -> Span {
match self.map.find(id) {
Some(ast_map::NodeExpr(e)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/dump_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
"<mutable>".to_string()
};
let types = self.tcx.node_types();
let typ = types.get(&id).unwrap().to_string();
let typ = types.get(&id).map(|t| t.to_string()).unwrap_or(String::new());
// Get the span only for the name of the variable (I hope the path
// is only ever a variable name, but who knows?).
let sub_span = self.span.span_for_last_ident(p.span);
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,15 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}

pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
let hir_node = lowering::lower_expr(self.lcx, expr);
let ty = self.tcx.expr_ty_adjusted_opt(&hir_node);
if ty.is_none() || ty.unwrap().sty == ty::TyError {
return None;
}
match expr.node {
ast::ExprField(ref sub_ex, ident) => {
let hir_node = lowering::lower_expr(self.lcx, sub_ex);
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
match *ty {
match self.tcx.expr_ty_adjusted(&hir_node).sty {
ty::TyStruct(def, _) => {
let f = def.struct_variant().field_named(ident.node.name);
let sub_span = self.span_utils.span_for_last_ident(expr.span);
Expand All @@ -487,8 +491,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
ast::ExprStruct(ref path, _, _) => {
let hir_node = lowering::lower_expr(self.lcx, expr);
let ty = &self.tcx.expr_ty_adjusted(&hir_node).sty;
match *ty {
match self.tcx.expr_ty_adjusted(&hir_node).sty {
ty::TyStruct(def, _) => {
let sub_span = self.span_utils.span_for_last_ident(path.span);
filter!(self.span_utils, sub_span, path.span, None);
Expand Down

0 comments on commit 4f97338

Please sign in to comment.