about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/typeck/check/mod.rs8
-rw-r--r--src/test/compile-fail/for-loop-bogosity.rs3
2 files changed, 6 insertions, 5 deletions
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index 230d8e95d8f..d8044ba96dd 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -2168,12 +2168,13 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt,
         }
     };
 
+    let expr_type = fcx.expr_ty(&*iterator_expr);
     let method = method::lookup_in_trait(fcx,
                                          iterator_expr.span,
                                          Some(&*iterator_expr),
                                          token::intern("next"),
                                          trait_did,
-                                         fcx.expr_ty(&*iterator_expr),
+                                         expr_type,
                                          [],
                                          DontAutoderefReceiver,
                                          IgnoreStaticMethods);
@@ -2184,8 +2185,9 @@ fn lookup_method_for_for_loop(fcx: &FnCtxt,
         Some(ref method) => method.ty,
         None => {
             fcx.tcx().sess.span_err(iterator_expr.span,
-                                    "`for` loop expression does not \
-                                     implement the `Iterator` trait");
+                                    format!("`for` loop expression has type `{}` which does \
+                                             not implement the `Iterator` trait",
+                                            fcx.infcx().ty_to_string(expr_type)).as_slice());
             ty::mk_err()
         }
     };
diff --git a/src/test/compile-fail/for-loop-bogosity.rs b/src/test/compile-fail/for-loop-bogosity.rs
index ba268cf3d64..67d07ca4bd1 100644
--- a/src/test/compile-fail/for-loop-bogosity.rs
+++ b/src/test/compile-fail/for-loop-bogosity.rs
@@ -24,8 +24,7 @@ pub fn main() {
         x: 1,
         y: 2,
     };
-    for x in bogus {    //~ ERROR does not implement the `Iterator` trait
+    for x in bogus { //~ ERROR has type `MyStruct` which does not implement the `Iterator` trait
         drop(x);
     }
 }
-