@@ -841,16 +841,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
841
841
return None ;
842
842
} ;
843
843
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 ( ) {
845
845
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 )
847
847
}
848
848
ty:: CoroutineClosure ( def_id, args) => (
849
849
def_id,
850
850
args. as_coroutine_closure ( )
851
851
. coroutine_closure_sig ( )
852
852
. 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 ( ) ,
854
855
) ,
855
856
_ => return None ,
856
857
} ;
@@ -884,10 +885,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
884
885
// If the closure has captures, then perhaps the reason that the trait
885
886
// is unimplemented is because async closures don't implement `Fn`/`FnMut`
886
887
// 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 {
891
889
let mut err = self . dcx ( ) . create_err ( AsyncClosureNotFn {
892
890
span : self . tcx . def_span ( closure_def_id) ,
893
891
kind : expected_kind. as_str ( ) ,
0 commit comments