From 9fcb6a2b883d5bee027e78fa462edd0ddc34f62b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 28 Nov 2016 10:08:29 -0800 Subject: [PATCH] Display better error messages for E0282 --- src/librustc/traits/error_reporting.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index bed834e237d..205a273df62 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -827,12 +827,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn need_type_info(&self, span: Span, ty: Ty<'tcx>) { + let ty = self.resolve_type_vars_if_possible(&ty); + 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, span, E0282, "unable to infer enough type information about `{}`", - ty); + name); err.note("type annotations or generic parameter binding required"); - err.span_label(span, &format!("cannot infer type for `{}`", ty)); - err.emit() + err.span_label(span, &format!("cannot infer type for `{}`", name)); + err.emit(); } fn note_obligation_cause(&self,