about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMasood Malekghassemi <atash@google.com>2016-04-13 07:48:53 -0700
committerMasood Malekghassemi <atash@google.com>2016-04-13 07:48:53 -0700
commitde82fc4dc6bbb87e50618f40e8fc671fb016f815 (patch)
tree04e92bb32817e11cf6cbc07b6ea98609529afd25 /src
parente45c7955e94fe55b7ca83dfb76b1bb50dfea74f6 (diff)
downloadrust-de82fc4dc6bbb87e50618f40e8fc671fb016f815.tar.gz
rust-de82fc4dc6bbb87e50618f40e8fc671fb016f815.zip
Fix obscure compilation error
Diffstat (limited to 'src')
-rw-r--r--src/librustc/diagnostics.rs2
-rw-r--r--src/librustc/traits/error_reporting.rs7
-rw-r--r--src/librustc_typeck/check/closure.rs13
-rw-r--r--src/test/compile-fail/closure-wrong-kind.rs3
4 files changed, 16 insertions, 9 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs
index ccba2df22eb..75411329516 100644
--- a/src/librustc/diagnostics.rs
+++ b/src/librustc/diagnostics.rs
@@ -1544,5 +1544,5 @@ register_diagnostics! {
     E0490, // a value of type `..` is borrowed for too long
     E0491, // in type `..`, reference has a longer lifetime than the data it...
     E0495, // cannot infer an appropriate lifetime due to conflicting requirements
-    E0524, // the closure implements `..` but not `..`
+    E0524, // expected a closure that implements `..` but this closure only implements `..`
 }
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index cb618af88f6..a40a5ce81c8 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -471,9 +471,10 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                         let closure_span = infcx.tcx.map.span_if_local(closure_def_id).unwrap();
                         let mut err = struct_span_err!(
                             infcx.tcx.sess, closure_span, E0524,
-                            "the closure implements `{}` but not `{}`",
-                            found_kind,
-                            kind);
+                            "expected a closure that implements the `{}` trait, but this closure \
+                             only implements `{}`",
+                            kind,
+                            found_kind);
                         err.span_note(
                             obligation.cause.span,
                             &format!("the requirement to implement `{}` derives from here", kind));
diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index 84c277a8a88..a2949ef30c8 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -179,9 +179,16 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
                 ty::Predicate::TypeOutlives(..) => None,
                 ty::Predicate::WellFormed(..) => None,
                 ty::Predicate::ObjectSafe(..) => None,
-                ty::Predicate::ClosureKind(_closure_def_id, kind) => {
-                    return Some(kind);
-                }
+
+                // NB: This predicate is created by breaking down a
+                // `ClosureType: FnFoo()` predicate, where
+                // `ClosureType` represents some `TyClosure`. It can't
+                // possibly be referring to the current closure,
+                // because we haven't produced the `TyClosure` for
+                // this closure yet; this is exactly why the other
+                // code is looking for a self type of a unresolved
+                // inference variable.
+                ty::Predicate::ClosureKind(..) => None,
             };
             opt_trait_ref
                 .and_then(|trait_ref| self_type_matches_expected_vid(fcx, trait_ref, expected_vid))
diff --git a/src/test/compile-fail/closure-wrong-kind.rs b/src/test/compile-fail/closure-wrong-kind.rs
index 4f06f56706b..6792414c367 100644
--- a/src/test/compile-fail/closure-wrong-kind.rs
+++ b/src/test/compile-fail/closure-wrong-kind.rs
@@ -17,7 +17,6 @@ fn bar<T: Fn(u32)>(_: T) {}
 
 fn main() {
     let x = X;
-    let closure = |_| foo(x);
-    //~^ ERROR the closure implements `FnOnce` but not `Fn`
+    let closure = |_| foo(x);  //~ ERROR E0524
     bar(closure);
 }