@@ -48,8 +48,13 @@ pub(crate) fn provide(providers: &mut Providers) {
4848 * providers = Providers {
4949 mir_keys,
5050 mir_const,
51- mir_const_qualif : |tcx, did| {
52- mir_const_qualif ( tcx, ty:: WithOptConstParam :: unknown ( did. expect_local ( ) ) )
51+ mir_const_qualif : |tcx, def_id| {
52+ let def_id = def_id. expect_local ( ) ;
53+ if let Some ( def) = ty:: WithOptConstParam :: try_lookup ( def_id, tcx) {
54+ tcx. mir_const_qualif_const_arg ( def)
55+ } else {
56+ mir_const_qualif ( tcx, ty:: WithOptConstParam :: unknown ( def_id) )
57+ }
5358 } ,
5459 mir_const_qualif_const_arg : |tcx, ( did, param_did) | {
5560 mir_const_qualif ( tcx, ty:: WithOptConstParam { did, const_param_did : Some ( param_did) } )
@@ -60,7 +65,12 @@ pub(crate) fn provide(providers: &mut Providers) {
6065 optimized_mir_of_const_arg,
6166 is_mir_available,
6267 promoted_mir : |tcx, def_id| {
63- promoted_mir ( tcx, ty:: WithOptConstParam :: unknown ( def_id. expect_local ( ) ) )
68+ let def_id = def_id. expect_local ( ) ;
69+ if let Some ( def) = ty:: WithOptConstParam :: try_lookup ( def_id, tcx) {
70+ tcx. promoted_mir_of_const_arg ( def)
71+ } else {
72+ promoted_mir ( tcx, ty:: WithOptConstParam :: unknown ( def_id) )
73+ }
6474 } ,
6575 promoted_mir_of_const_arg : |tcx, ( did, param_did) | {
6676 promoted_mir ( tcx, ty:: WithOptConstParam { did, const_param_did : Some ( param_did) } )
@@ -221,12 +231,6 @@ pub fn run_passes(
221231}
222232
223233fn mir_const_qualif ( tcx : TyCtxt < ' _ > , def : ty:: WithOptConstParam < LocalDefId > ) -> ConstQualifs {
224- if def. const_param_did . is_none ( ) {
225- if let Some ( param_did) = tcx. opt_const_param_of ( def. did ) {
226- return tcx. mir_const_qualif_const_arg ( ( def. did , param_did) ) ;
227- }
228- }
229-
230234 let const_kind = tcx. hir ( ) . body_const_context ( def. did ) ;
231235
232236 // No need to const-check a non-const `fn`.
@@ -266,10 +270,8 @@ fn mir_const<'tcx>(
266270 tcx : TyCtxt < ' tcx > ,
267271 def : ty:: WithOptConstParam < LocalDefId > ,
268272) -> & ' tcx Steal < Body < ' tcx > > {
269- if def. const_param_did . is_none ( ) {
270- if let const_param_did @ Some ( _) = tcx. opt_const_param_of ( def. did ) {
271- return tcx. mir_const ( ty:: WithOptConstParam { const_param_did, ..def } ) ;
272- }
273+ if let Some ( def) = def. try_upgrade ( tcx) {
274+ return tcx. mir_const ( def) ;
273275 }
274276
275277 // Unsafety check uses the raw mir, so make sure it is run.
@@ -312,10 +314,8 @@ fn mir_validated(
312314 tcx : TyCtxt < ' tcx > ,
313315 def : ty:: WithOptConstParam < LocalDefId > ,
314316) -> ( & ' tcx Steal < Body < ' tcx > > , & ' tcx Steal < IndexVec < Promoted , Body < ' tcx > > > ) {
315- if def. const_param_did . is_none ( ) {
316- if let const_param_did @ Some ( _) = tcx. opt_const_param_of ( def. did ) {
317- return tcx. mir_validated ( ty:: WithOptConstParam { const_param_did, ..def } ) ;
318- }
317+ if let Some ( def) = def. try_upgrade ( tcx) {
318+ return tcx. mir_validated ( def) ;
319319 }
320320
321321 // Ensure that we compute the `mir_const_qualif` for constants at
@@ -357,13 +357,8 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
357357 tcx : TyCtxt < ' tcx > ,
358358 def : ty:: WithOptConstParam < LocalDefId > ,
359359) -> & ' tcx Steal < Body < ' tcx > > {
360- if def. const_param_did . is_none ( ) {
361- if let const_param_did @ Some ( _) = tcx. opt_const_param_of ( def. did ) {
362- return tcx. mir_drops_elaborated_and_const_checked ( ty:: WithOptConstParam {
363- const_param_did,
364- ..def
365- } ) ;
366- }
360+ if let Some ( def) = def. try_upgrade ( tcx) {
361+ return tcx. mir_drops_elaborated_and_const_checked ( def) ;
367362 }
368363
369364 // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
@@ -490,8 +485,8 @@ fn run_optimization_passes<'tcx>(
490485
491486fn optimized_mir < ' tcx > ( tcx : TyCtxt < ' tcx > , did : DefId ) -> & ' tcx Body < ' tcx > {
492487 let did = did. expect_local ( ) ;
493- if let Some ( param_did ) = tcx . opt_const_param_of ( did) {
494- tcx. optimized_mir_of_const_arg ( ( did , param_did ) )
488+ if let Some ( def ) = ty :: WithOptConstParam :: try_lookup ( did, tcx ) {
489+ tcx. optimized_mir_of_const_arg ( def )
495490 } else {
496491 tcx. arena . alloc ( inner_optimized_mir ( tcx, ty:: WithOptConstParam :: unknown ( did) ) )
497492 }
@@ -528,12 +523,6 @@ fn promoted_mir<'tcx>(
528523 tcx : TyCtxt < ' tcx > ,
529524 def : ty:: WithOptConstParam < LocalDefId > ,
530525) -> & ' tcx IndexVec < Promoted , Body < ' tcx > > {
531- if def. const_param_did . is_none ( ) {
532- if let Some ( param_did) = tcx. opt_const_param_of ( def. did ) {
533- return tcx. promoted_mir_of_const_arg ( ( def. did , param_did) ) ;
534- }
535- }
536-
537526 if tcx. is_constructor ( def. did . to_def_id ( ) ) {
538527 return tcx. arena . alloc ( IndexVec :: new ( ) ) ;
539528 }
0 commit comments