@@ -841,16 +841,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
841841 return None ;
842842 } ;
843843
844- let ( closure_def_id, found_args, by_ref_captures ) = match * self_ty. kind ( ) {
844+ let ( closure_def_id, found_args, has_self_borrows ) = match * self_ty. kind ( ) {
845845 ty:: Closure ( def_id, args) => {
846- ( def_id, args. as_closure ( ) . sig ( ) . map_bound ( |sig| sig. inputs ( ) [ 0 ] ) , None )
846+ ( def_id, args. as_closure ( ) . sig ( ) . map_bound ( |sig| sig. inputs ( ) [ 0 ] ) , false )
847847 }
848848 ty:: CoroutineClosure ( def_id, args) => (
849849 def_id,
850850 args. as_coroutine_closure ( )
851851 . coroutine_closure_sig ( )
852852 . map_bound ( |sig| sig. tupled_inputs_ty ) ,
853- Some ( args. as_coroutine_closure ( ) . coroutine_captures_by_ref_ty ( ) ) ,
853+ !args. as_coroutine_closure ( ) . tupled_upvars_ty ( ) . is_ty_var ( )
854+ && args. as_coroutine_closure ( ) . has_self_borrows ( ) ,
854855 ) ,
855856 _ => return None ,
856857 } ;
@@ -884,10 +885,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
884885 // If the closure has captures, then perhaps the reason that the trait
885886 // is unimplemented is because async closures don't implement `Fn`/`FnMut`
886887 // if they have captures.
887- if let Some ( by_ref_captures) = by_ref_captures
888- && let ty:: FnPtr ( sig_tys, _) = by_ref_captures. kind ( )
889- && !sig_tys. skip_binder ( ) . output ( ) . is_unit ( )
890- {
888+ if has_self_borrows && expected_kind != ty:: ClosureKind :: FnOnce {
891889 let mut err = self . dcx ( ) . create_err ( AsyncClosureNotFn {
892890 span : self . tcx . def_span ( closure_def_id) ,
893891 kind : expected_kind. as_str ( ) ,
0 commit comments