@@ -235,7 +235,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
235235}
236236
237237/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
238- fn mir_const ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Steal < Body < ' _ > > {
238+ fn mir_const < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> & ' tcx Steal < Body < ' tcx > > {
239239 let def_id = def_id. expect_local ( ) ;
240240
241241 // Unsafety check uses the raw mir, so make sure it is run.
@@ -267,7 +267,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
267267fn mir_validated (
268268 tcx : TyCtxt < ' tcx > ,
269269 def_id : LocalDefId ,
270- ) -> ( Steal < Body < ' tcx > > , Steal < IndexVec < Promoted , Body < ' tcx > > > ) {
270+ ) -> ( & ' tcx Steal < Body < ' tcx > > , & ' tcx Steal < IndexVec < Promoted , Body < ' tcx > > > ) {
271271 // Ensure that we compute the `mir_const_qualif` for constants at
272272 // this point, before we steal the mir-const result.
273273 let _ = tcx. mir_const_qualif ( def_id. to_def_id ( ) ) ;
@@ -305,17 +305,24 @@ fn mir_validated(
305305
306306fn mir_drops_elaborated_and_const_checked < ' tcx > (
307307 tcx : TyCtxt < ' tcx > ,
308- def_id : LocalDefId ,
309- ) -> Steal < Body < ' tcx > > {
308+ def : ty:: WithOptParam < LocalDefId > ,
309+ ) -> & ' tcx Steal < Body < ' tcx > > {
310+ if def. param_did . is_none ( ) {
311+ if let param_did @ Some ( _) = tcx. opt_const_param_of ( def. did ) {
312+ return tcx
313+ . mir_drops_elaborated_and_const_checked ( ty:: WithOptParam { param_did, ..def } ) ;
314+ }
315+ }
316+
310317 // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
311318 // execute before we can steal.
312- tcx. ensure ( ) . mir_borrowck ( def_id ) ;
319+ tcx. ensure ( ) . mir_borrowck ( def . did ) ;
313320
314- let ( body, _) = tcx. mir_validated ( def_id ) ;
321+ let ( body, _) = tcx. mir_validated ( def . did ) ;
315322 let mut body = body. steal ( ) ;
316323
317- run_post_borrowck_cleanup_passes ( tcx, & mut body, def_id , None ) ;
318- check_consts:: post_drop_elaboration:: check_live_drops ( tcx, def_id , & body) ;
324+ run_post_borrowck_cleanup_passes ( tcx, & mut body, def . did , None ) ;
325+ check_consts:: post_drop_elaboration:: check_live_drops ( tcx, def . did , & body) ;
319326 tcx. alloc_steal_mir ( body)
320327}
321328
@@ -458,7 +465,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam<LocalDefId>) -> Bo
458465 return shim:: build_adt_ctor ( tcx, def. did . to_def_id ( ) ) ;
459466 }
460467
461- let mut body = tcx. mir_drops_elaborated_and_const_checked ( def. did ) . steal ( ) ;
468+ let mut body = tcx. mir_drops_elaborated_and_const_checked ( def) . steal ( ) ;
462469 run_optimization_passes ( tcx, & mut body, def. did , None ) ;
463470
464471 debug_assert ! ( !body. has_free_regions( ) , "Free regions in optimized MIR" ) ;
0 commit comments