@@ -47,8 +47,6 @@ pub(crate) fn mir_built(
47
47
48
48
/// Construct the MIR for a given `DefId`.
49
49
fn mir_build ( tcx : TyCtxt < ' _ > , def : ty:: WithOptConstParam < LocalDefId > ) -> Body < ' _ > {
50
- let body_owner_kind = tcx. hir ( ) . body_owner_kind ( def. did ) ;
51
-
52
50
// Ensure unsafeck and abstract const building is ran before we steal the THIR.
53
51
// We can't use `ensure()` for `thir_abstract_const` as it doesn't compute the query
54
52
// 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<'_
65
63
}
66
64
67
65
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) ,
69
67
Ok ( ( thir, expr) ) => {
70
68
// We ran all queries that depended on THIR at the beginning
71
69
// of `mir_build`, so now we can steal it
72
70
let thir = thir. steal ( ) ;
73
71
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) ,
78
75
}
79
76
}
80
77
} ;
@@ -434,6 +431,7 @@ fn construct_fn<'tcx>(
434
431
fn_def : ty:: WithOptConstParam < LocalDefId > ,
435
432
thir : & Thir < ' tcx > ,
436
433
expr : ExprId ,
434
+ fn_sig : ty:: FnSig < ' tcx > ,
437
435
) -> Body < ' tcx > {
438
436
let span = tcx. def_span ( fn_def. did ) ;
439
437
let fn_id = tcx. hir ( ) . local_def_id_to_hir_id ( fn_def. did ) ;
@@ -453,11 +451,6 @@ fn construct_fn<'tcx>(
453
451
. output
454
452
. span ( ) ;
455
453
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
-
461
454
let safety = match fn_sig. unsafety {
462
455
hir:: Unsafety :: Normal => Safety :: Safe ,
463
456
hir:: Unsafety :: Unsafe => Safety :: FnUnsafe ,
@@ -563,6 +556,7 @@ fn construct_const<'a, 'tcx>(
563
556
def : ty:: WithOptConstParam < LocalDefId > ,
564
557
thir : & ' a Thir < ' tcx > ,
565
558
expr : ExprId ,
559
+ const_ty : Ty < ' tcx > ,
566
560
) -> Body < ' tcx > {
567
561
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
568
562
@@ -586,20 +580,6 @@ fn construct_const<'a, 'tcx>(
586
580
_ => span_bug ! ( tcx. def_span( def. did) , "can't build MIR for {:?}" , def. did) ,
587
581
} ;
588
582
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
-
603
583
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
604
584
let mut builder = Builder :: new (
605
585
thir,
@@ -629,15 +609,11 @@ fn construct_const<'a, 'tcx>(
629
609
///
630
610
/// This is required because we may still want to run MIR passes on an item
631
611
/// 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 < ' _ > {
638
613
let span = tcx. def_span ( def) ;
639
614
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def) ;
640
615
let generator_kind = tcx. generator_kind ( def) ;
616
+ let body_owner_kind = tcx. hir ( ) . body_owner_kind ( def) ;
641
617
642
618
let ty = tcx. ty_error ( err) ;
643
619
let num_params = match body_owner_kind {
0 commit comments