@@ -371,7 +371,7 @@ pub struct ClosureSubsts<'tcx> {
371371/// parent slice and not canonical substs themselves.
372372struct SplitClosureSubsts < ' tcx > {
373373 closure_kind_ty : Ty < ' tcx > ,
374- closure_sig_ty : Ty < ' tcx > ,
374+ closure_sig_as_fn_ptr_ty : Ty < ' tcx > ,
375375 upvar_kinds : & ' tcx [ GenericArg < ' tcx > ] ,
376376}
377377
@@ -384,7 +384,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
384384 let parent_len = generics. parent_count ;
385385 SplitClosureSubsts {
386386 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 ) ,
388388 upvar_kinds : & self . substs [ parent_len + 2 ..] ,
389389 }
390390 }
@@ -412,12 +412,10 @@ impl<'tcx> ClosureSubsts<'tcx> {
412412 self . split ( def_id, tcx) . closure_kind_ty
413413 }
414414
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
421419 }
422420
423421 /// Returns the closure kind for this closure; only usable outside
@@ -429,16 +427,12 @@ impl<'tcx> ClosureSubsts<'tcx> {
429427 self . split ( def_id, tcx) . closure_kind_ty . to_opt_closure_kind ( ) . unwrap ( )
430428 }
431429
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.
437431 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) ;
439433 match ty. kind {
440434 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) ,
442436 }
443437 }
444438}
@@ -2200,9 +2194,9 @@ impl<'tcx> TyS<'tcx> {
22002194 // ignore errors (#54954)
22012195 ty:: Binder :: dummy ( FnSig :: fake ( ) )
22022196 }
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+ ) ,
22062200 _ => bug ! ( "Ty::fn_sig() called on non-fn type: {:?}" , self ) ,
22072201 }
22082202 }
0 commit comments