Skip to content

Commit

Permalink
Fix obscure compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanmm-google committed Apr 13, 2016
1 parent e45c795 commit de82fc4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `..`
}
7 changes: 4 additions & 3 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 10 additions & 3 deletions src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/closure-wrong-kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit de82fc4

Please sign in to comment.