about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2016-11-28 10:08:29 -0800
committerKeith Yeung <kungfukeith11@gmail.com>2016-12-03 17:12:31 -0800
commit9fcb6a2b883d5bee027e78fa462edd0ddc34f62b (patch)
tree0052f27820f7738d260a38ce012b8b63cbac2225 /src
parent3d069e1b38c983e846ea8db1f07af729bdc79fe7 (diff)
downloadrust-9fcb6a2b883d5bee027e78fa462edd0ddc34f62b.tar.gz
rust-9fcb6a2b883d5bee027e78fa462edd0ddc34f62b.zip
Display better error messages for E0282
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/error_reporting.rs20
1 files 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<T>(&self,