@@ -371,7 +371,7 @@ pub struct ClosureSubsts<'tcx> {
371
371
/// parent slice and not canonical substs themselves.
372
372
struct SplitClosureSubsts < ' tcx > {
373
373
closure_kind_ty : Ty < ' tcx > ,
374
- closure_sig_ty : Ty < ' tcx > ,
374
+ closure_sig_as_fn_ptr_ty : Ty < ' tcx > ,
375
375
upvar_kinds : & ' tcx [ GenericArg < ' tcx > ] ,
376
376
}
377
377
@@ -384,7 +384,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
384
384
let parent_len = generics. parent_count ;
385
385
SplitClosureSubsts {
386
386
closure_kind_ty : self . substs . type_at ( parent_len) ,
387
- closure_sig_ty : self . substs . type_at ( parent_len + 1 ) ,
387
+ closure_sig_as_fn_ptr_ty : self . substs . type_at ( parent_len + 1 ) ,
388
388
upvar_kinds : & self . substs [ parent_len + 2 ..] ,
389
389
}
390
390
}
@@ -412,12 +412,10 @@ impl<'tcx> ClosureSubsts<'tcx> {
412
412
self . split ( def_id, tcx) . closure_kind_ty
413
413
}
414
414
415
- /// Returns the type representing the closure signature for this
416
- /// closure; may contain type variables during inference. To get
417
- /// the closure signature during inference, use
418
- /// `infcx.fn_sig(def_id)`.
419
- pub fn sig_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ > ) -> Ty < ' tcx > {
420
- self . split ( def_id, tcx) . closure_sig_ty
415
+ /// Returns the `fn` pointer type representing the closure signature for this
416
+ /// closure.
417
+ pub fn sig_as_fn_ptr_ty ( self , def_id : DefId , tcx : TyCtxt < ' _ > ) -> Ty < ' tcx > {
418
+ self . split ( def_id, tcx) . closure_sig_as_fn_ptr_ty
421
419
}
422
420
423
421
/// Returns the closure kind for this closure; only usable outside
@@ -429,16 +427,12 @@ impl<'tcx> ClosureSubsts<'tcx> {
429
427
self . split ( def_id, tcx) . closure_kind_ty . to_opt_closure_kind ( ) . unwrap ( )
430
428
}
431
429
432
- /// Extracts the signature from the closure; only usable outside
433
- /// of an inference context, because in that context we know that
434
- /// there are no type variables.
435
- ///
436
- /// If you have an inference context, use `infcx.closure_sig()`.
430
+ /// Extracts the signature from the closure.
437
431
pub fn sig ( & self , def_id : DefId , tcx : TyCtxt < ' tcx > ) -> ty:: PolyFnSig < ' tcx > {
438
- let ty = self . sig_ty ( def_id, tcx) ;
432
+ let ty = self . sig_as_fn_ptr_ty ( def_id, tcx) ;
439
433
match ty. kind {
440
434
ty:: FnPtr ( sig) => sig,
441
- _ => bug ! ( "closure_sig_ty is not a fn-ptr: {:?}" , ty. kind) ,
435
+ _ => bug ! ( "closure_sig_as_fn_ptr_ty is not a fn-ptr: {:?}" , ty. kind) ,
442
436
}
443
437
}
444
438
}
@@ -2200,9 +2194,9 @@ impl<'tcx> TyS<'tcx> {
2200
2194
// ignore errors (#54954)
2201
2195
ty:: Binder :: dummy ( FnSig :: fake ( ) )
2202
2196
}
2203
- Closure ( ..) => {
2204
- bug ! ( "to get the signature of a closure, use `closure_sig() ` not `fn_sig()`" , )
2205
- }
2197
+ Closure ( ..) => bug ! (
2198
+ "to get the signature of a closure, use `substs.as_closure().sig() ` not `fn_sig()`" ,
2199
+ ) ,
2206
2200
_ => bug ! ( "Ty::fn_sig() called on non-fn type: {:?}" , self ) ,
2207
2201
}
2208
2202
}
0 commit comments