})
}
+ 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)) => {
"<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);
}
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);
}
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);