@@ -47,8 +47,6 @@ pub(crate) fn mir_built(
4747
4848/// Construct the MIR for a given `DefId`.
4949fn mir_build ( tcx : TyCtxt < ' _ > , def : ty:: WithOptConstParam < LocalDefId > ) -> Body < ' _ > {
50- let body_owner_kind = tcx. hir ( ) . body_owner_kind ( def. did ) ;
51-
5250 // Ensure unsafeck and abstract const building is ran before we steal the THIR.
5351 // We can't use `ensure()` for `thir_abstract_const` as it doesn't compute the query
5452 // if inputs are green. This can cause ICEs when calling `thir_abstract_const` after
@@ -65,16 +63,15 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
6563 }
6664
6765 let body = match tcx. thir_body ( def) {
68- Err ( error_reported) => construct_error ( tcx, def. did , body_owner_kind , error_reported) ,
66+ Err ( error_reported) => construct_error ( tcx, def. did , error_reported) ,
6967 Ok ( ( thir, expr) ) => {
7068 // We ran all queries that depended on THIR at the beginning
7169 // of `mir_build`, so now we can steal it
7270 let thir = thir. steal ( ) ;
7371
74- if body_owner_kind. is_fn_or_closure ( ) {
75- construct_fn ( tcx, def, & thir, expr)
76- } else {
77- construct_const ( tcx, def, & thir, expr)
72+ match thir. body_type {
73+ thir:: BodyTy :: Fn ( fn_sig) => construct_fn ( tcx, def, & thir, expr, fn_sig) ,
74+ thir:: BodyTy :: Const ( ty) => construct_const ( tcx, def, & thir, expr, ty) ,
7875 }
7976 }
8077 } ;
@@ -434,6 +431,7 @@ fn construct_fn<'tcx>(
434431 fn_def : ty:: WithOptConstParam < LocalDefId > ,
435432 thir : & Thir < ' tcx > ,
436433 expr : ExprId ,
434+ fn_sig : ty:: FnSig < ' tcx > ,
437435) -> Body < ' tcx > {
438436 let span = tcx. def_span ( fn_def. did ) ;
439437 let fn_id = tcx. hir ( ) . local_def_id_to_hir_id ( fn_def. did ) ;
@@ -453,11 +451,6 @@ fn construct_fn<'tcx>(
453451 . output
454452 . span ( ) ;
455453
456- // fetch the fully liberated fn signature (that is, all bound
457- // types/lifetimes replaced)
458- let typeck_results = tcx. typeck_opt_const_arg ( fn_def) ;
459- let fn_sig = typeck_results. liberated_fn_sigs ( ) [ fn_id] ;
460-
461454 let safety = match fn_sig. unsafety {
462455 hir:: Unsafety :: Normal => Safety :: Safe ,
463456 hir:: Unsafety :: Unsafe => Safety :: FnUnsafe ,
@@ -563,6 +556,7 @@ fn construct_const<'a, 'tcx>(
563556 def : ty:: WithOptConstParam < LocalDefId > ,
564557 thir : & ' a Thir < ' tcx > ,
565558 expr : ExprId ,
559+ const_ty : Ty < ' tcx > ,
566560) -> Body < ' tcx > {
567561 let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
568562
@@ -586,20 +580,6 @@ fn construct_const<'a, 'tcx>(
586580 _ => span_bug ! ( tcx. def_span( def. did) , "can't build MIR for {:?}" , def. did) ,
587581 } ;
588582
589- // Get the revealed type of this const. This is *not* the adjusted
590- // type of its body, which may be a subtype of this type. For
591- // example:
592- //
593- // fn foo(_: &()) {}
594- // static X: fn(&'static ()) = foo;
595- //
596- // The adjusted type of the body of X is `for<'a> fn(&'a ())` which
597- // is not the same as the type of X. We need the type of the return
598- // place to be the type of the constant because NLL typeck will
599- // equate them.
600- let typeck_results = tcx. typeck_opt_const_arg ( def) ;
601- let const_ty = typeck_results. node_type ( hir_id) ;
602-
603583 let infcx = tcx. infer_ctxt ( ) . build ( ) ;
604584 let mut builder = Builder :: new (
605585 thir,
@@ -629,15 +609,11 @@ fn construct_const<'a, 'tcx>(
629609///
630610/// This is required because we may still want to run MIR passes on an item
631611/// with type errors, but normal MIR construction can't handle that in general.
632- fn construct_error (
633- tcx : TyCtxt < ' _ > ,
634- def : LocalDefId ,
635- body_owner_kind : hir:: BodyOwnerKind ,
636- err : ErrorGuaranteed ,
637- ) -> Body < ' _ > {
612+ fn construct_error ( tcx : TyCtxt < ' _ > , def : LocalDefId , err : ErrorGuaranteed ) -> Body < ' _ > {
638613 let span = tcx. def_span ( def) ;
639614 let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def) ;
640615 let generator_kind = tcx. generator_kind ( def) ;
616+ let body_owner_kind = tcx. hir ( ) . body_owner_kind ( def) ;
641617
642618 let ty = tcx. ty_error ( err) ;
643619 let num_params = match body_owner_kind {
0 commit comments