@@ -14,7 +14,7 @@ use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
14
14
use rustc_middle:: ty:: GenericArgs ;
15
15
use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeSuperVisitable , TypeVisitor } ;
16
16
use rustc_span:: def_id:: LocalDefId ;
17
- use rustc_span:: { sym , Span } ;
17
+ use rustc_span:: Span ;
18
18
use rustc_target:: spec:: abi:: Abi ;
19
19
use rustc_trait_selection:: traits;
20
20
use rustc_trait_selection:: traits:: error_reporting:: ArgKind ;
@@ -49,7 +49,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49
49
expr_span : Span ,
50
50
expected : Expectation < ' tcx > ,
51
51
) -> Ty < ' tcx > {
52
- trace ! ( "decl = {:#?}" , closure. fn_decl) ;
52
+ let tcx = self . tcx ;
53
+ let body = tcx. hir ( ) . body ( closure. body ) ;
54
+ let expr_def_id = closure. def_id ;
53
55
54
56
// It's always helpful for inference if we know the kind of
55
57
// closure sooner rather than later, so first examine the expected
@@ -61,24 +63,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
61
63
None => ( None , None ) ,
62
64
} ;
63
65
64
- self . check_closure ( closure, expr_span, expected_kind, expected_sig)
65
- }
66
-
67
- #[ instrument( skip( self , closure) , level = "debug" , ret) ]
68
- fn check_closure (
69
- & self ,
70
- closure : & hir:: Closure < ' tcx > ,
71
- expr_span : Span ,
72
- opt_kind : Option < ty:: ClosureKind > ,
73
- expected_sig : Option < ExpectedSig < ' tcx > > ,
74
- ) -> Ty < ' tcx > {
75
- let tcx = self . tcx ;
76
- let body = tcx. hir ( ) . body ( closure. body ) ;
77
-
78
- trace ! ( "decl = {:#?}" , closure. fn_decl) ;
79
- let expr_def_id = closure. def_id ;
80
- debug ! ( ?expr_def_id) ;
81
-
82
66
let ClosureSignatures { bound_sig, liberated_sig } =
83
67
self . sig_of_closure ( expr_def_id, closure. fn_decl , closure. kind , expected_sig) ;
84
68
@@ -139,9 +123,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139
123
}
140
124
} ;
141
125
142
- let mut fcx = FnCtxt :: new ( self , self . param_env , closure. def_id ) ;
143
126
check_fn (
144
- & mut fcx ,
127
+ & mut FnCtxt :: new ( self , self . param_env , closure . def_id ) ,
145
128
liberated_sig,
146
129
coroutine_types,
147
130
closure. fn_decl ,
@@ -174,9 +157,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174
157
)
175
158
} ) ;
176
159
177
- debug ! ( ?sig, ?opt_kind ) ;
160
+ debug ! ( ?sig, ?expected_kind ) ;
178
161
179
- let closure_kind_ty = match opt_kind {
162
+ let closure_kind_ty = match expected_kind {
180
163
Some ( kind) => Ty :: from_closure_kind ( tcx, kind) ,
181
164
182
165
// Create a type variable (for now) to represent the closure kind.
@@ -204,11 +187,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204
187
let Some ( CoroutineTypes { resume_ty, yield_ty } ) = coroutine_types else {
205
188
bug ! ( "expected coroutine to have yield/resume types" ) ;
206
189
} ;
207
- let interior = fcx . next_ty_var ( TypeVariableOrigin {
190
+ let interior = self . next_ty_var ( TypeVariableOrigin {
208
191
kind : TypeVariableOriginKind :: MiscVariable ,
209
192
span : body. value . span ,
210
193
} ) ;
211
- fcx . deferred_coroutine_interiors . borrow_mut ( ) . push ( (
194
+ self . deferred_coroutine_interiors . borrow_mut ( ) . push ( (
212
195
expr_def_id,
213
196
body. id ( ) ,
214
197
interior,
@@ -364,36 +347,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
364
347
let tcx = self . tcx ;
365
348
366
349
let trait_def_id = projection. trait_def_id ( tcx) ;
367
-
368
- let is_fn = tcx. is_fn_trait ( trait_def_id) ;
369
-
370
- let coroutine_trait = tcx. lang_items ( ) . coroutine_trait ( ) ;
371
- let is_gen = coroutine_trait == Some ( trait_def_id) ;
372
-
373
- if !is_fn && !is_gen {
374
- debug ! ( "not fn or coroutine" ) ;
350
+ // For now, we only do signature deduction based off of the `Fn` traits.
351
+ if !tcx. is_fn_trait ( trait_def_id) {
375
352
return None ;
376
353
}
377
354
378
- // Check that we deduce the signature from the `<_ as std::ops::Coroutine>::Return`
379
- // associated item and not yield.
380
- if is_gen && self . tcx . associated_item ( projection. projection_def_id ( ) ) . name != sym:: Return {
381
- debug ! ( "not `Return` assoc item of `Coroutine`" ) ;
382
- return None ;
383
- }
384
-
385
- let input_tys = if is_fn {
386
- let arg_param_ty = projection. skip_binder ( ) . projection_ty . args . type_at ( 1 ) ;
387
- let arg_param_ty = self . resolve_vars_if_possible ( arg_param_ty) ;
388
- debug ! ( ?arg_param_ty) ;
355
+ let arg_param_ty = projection. skip_binder ( ) . projection_ty . args . type_at ( 1 ) ;
356
+ let arg_param_ty = self . resolve_vars_if_possible ( arg_param_ty) ;
357
+ debug ! ( ?arg_param_ty) ;
389
358
390
- match arg_param_ty. kind ( ) {
391
- & ty:: Tuple ( tys) => tys,
392
- _ => return None ,
393
- }
394
- } else {
395
- // Coroutines with a `()` resume type may be defined with 0 or 1 explicit arguments,
396
- // else they must have exactly 1 argument. For now though, just give up in this case.
359
+ let ty:: Tuple ( input_tys) = * arg_param_ty. kind ( ) else {
397
360
return None ;
398
361
} ;
399
362
0 commit comments