Some changes to save-analysis to cope with errors
This commit is contained in:
parent
6bd782c4ca
commit
4f97338a3a
|
@ -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)) => {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue