@@ -37,9 +37,7 @@ use super::{
3737use crate :: error_reporting:: TypeErrCtxt ;
3838use crate :: error_reporting:: infer:: TyCategory ;
3939use 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 } ;
4341use crate :: infer:: { self , InferCtxt , InferCtxtExt as _} ;
4442use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
4543use crate :: traits:: {
@@ -887,15 +885,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
887885 }
888886
889887 // 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`
891889 // if they have captures.
892890 if let Some ( by_ref_captures) = by_ref_captures
893891 && let ty:: FnPtr ( sig_tys, _) = by_ref_captures. kind ( )
894892 && !sig_tys. skip_binder ( ) . output ( ) . is_unit ( )
895893 {
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 {
897903 span : self . tcx . def_span ( closure_def_id) ,
898904 kind : expected_kind. as_str ( ) ,
905+ coro_kind,
899906 } ) ;
900907 self . note_obligation_cause ( & mut err, & obligation) ;
901908 return Some ( err. emit ( ) ) ;
0 commit comments