@@ -37,9 +37,7 @@ use super::{
37
37
use crate :: error_reporting:: TypeErrCtxt ;
38
38
use crate :: error_reporting:: infer:: TyCategory ;
39
39
use crate :: error_reporting:: traits:: report_dyn_incompatibility;
40
- use crate :: errors:: {
41
- AsyncClosureNotFn , ClosureFnMutLabel , ClosureFnOnceLabel , ClosureKindMismatch ,
42
- } ;
40
+ use crate :: errors:: { ClosureFnMutLabel , ClosureFnOnceLabel , ClosureKindMismatch , CoroClosureNotFn } ;
43
41
use crate :: infer:: { self , InferCtxt , InferCtxtExt as _} ;
44
42
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
45
43
use crate :: traits:: {
@@ -887,15 +885,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
887
885
}
888
886
889
887
// If the closure has captures, then perhaps the reason that the trait
890
- // is unimplemented is because async closures don't implement `Fn`/`FnMut`
888
+ // is unimplemented is because coro closures don't implement `Fn`/`FnMut`
891
889
// if they have captures.
892
890
if let Some ( by_ref_captures) = by_ref_captures
893
891
&& let ty:: FnPtr ( sig_tys, _) = by_ref_captures. kind ( )
894
892
&& !sig_tys. skip_binder ( ) . output ( ) . is_unit ( )
895
893
{
896
- let mut err = self . dcx ( ) . create_err ( AsyncClosureNotFn {
894
+ let coro_kind = match self
895
+ . tcx
896
+ . coroutine_kind ( self . tcx . coroutine_for_closure ( closure_def_id) )
897
+ . unwrap ( )
898
+ {
899
+ rustc_hir:: CoroutineKind :: Desugared ( desugaring, _) => desugaring. to_string ( ) ,
900
+ coro => coro. to_string ( ) ,
901
+ } ;
902
+ let mut err = self . dcx ( ) . create_err ( CoroClosureNotFn {
897
903
span : self . tcx . def_span ( closure_def_id) ,
898
904
kind : expected_kind. as_str ( ) ,
905
+ coro_kind,
899
906
} ) ;
900
907
self . note_obligation_cause ( & mut err, & obligation) ;
901
908
return Some ( err. emit ( ) ) ;
0 commit comments