Skip to content

Instantly share code, notes, and snippets.

@cengiz-io
Last active January 23, 2017 17:52
Show Gist options
  • Save cengiz-io/4d09dbd0572709514183edc734d7f2d6 to your computer and use it in GitHub Desktop.
Save cengiz-io/4d09dbd0572709514183edc734d7f2d6 to your computer and use it in GitHub Desktop.
pub struct Dummy {}
impl Dummy {
pub fn new() -> Dummy {
Dummy {}
}
}
impl<'a, 'gcx, 'tcx> Visitor<'a> for Dummy {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'a> {
NestedVisitorMap::None
}
fn visit_expr(&mut self, expr: &'a Expr) {
debug!("visit_expr: {:?}", expr);
}
}
// Other code goes here
fn need_type_info(&self, cause: &ObligationCause<'tcx>, ty: Ty<'tcx>) {
let ty = self.resolve_type_vars_if_possible(&ty);
let body_id = cause.body_id;
let expr = self.tcx.map.expect_expr(body_id);
debug!("\nExpr: {:?}\n", expr);
let mut dummy = Dummy::new();
dummy.visit_expr(expr);
let name = if let ty::TyInfer(ty::TyVar(ty_vid)) = ty.sty {
let ty_vars = self.type_variables.borrow();
if let TypeVariableOrigin::TypeParameterDefinition(_, name) =
*ty_vars.var_origin(ty_vid)
{
name.to_string()
} else {
ty.to_string()
}
} else {
ty.to_string()
};
let mut err = struct_span_err!(self.tcx.sess, cause.span, E0282,
"unable to infer enough type information about `{}`",
name);
err.note("type annotations or generic parameter binding required");
err.span_label(cause.span, &format!("cannot infer type for `{}`", name));
err.emit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment