@@ -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:: {
@@ -904,9 +902,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
904
902
&& let ty:: FnPtr ( sig_tys, _) = by_ref_captures. kind ( )
905
903
&& !sig_tys. skip_binder ( ) . output ( ) . is_unit ( )
906
904
{
907
- let mut err = self . dcx ( ) . create_err ( AsyncClosureNotFn {
905
+ let coro_kind = match self
906
+ . tcx
907
+ . coroutine_kind ( self . tcx . coroutine_for_closure ( closure_def_id) )
908
+ . unwrap ( )
909
+ {
910
+ rustc_hir:: CoroutineKind :: Desugared ( desugaring, _) => format ! ( "{desugaring:#}" ) ,
911
+ coro => format ! ( "{coro:#}" ) ,
912
+ } ;
913
+ let mut err = self . dcx ( ) . create_err ( CoroClosureNotFn {
908
914
span : self . tcx . def_span ( closure_def_id) ,
909
915
kind : expected_kind. as_str ( ) ,
916
+ coro_kind,
910
917
} ) ;
911
918
self . note_obligation_cause ( & mut err, & obligation) ;
912
919
return Some ( err. emit ( ) ) ;
0 commit comments