Fix obscure compilation error

This commit is contained in:
Masood Malekghassemi 2016-04-13 07:48:53 -07:00
parent e45c7955e9
commit de82fc4dc6
4 changed files with 16 additions and 9 deletions

View File

@ -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 `..`
}

View File

@ -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));

View File

@ -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))

View File

@ -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);
}