@@ -48,8 +48,13 @@ pub(crate) fn provide(providers: &mut Providers) {
48
48
* providers = Providers {
49
49
mir_keys,
50
50
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
+ }
53
58
} ,
54
59
mir_const_qualif_const_arg : |tcx, ( did, param_did) | {
55
60
mir_const_qualif ( tcx, ty:: WithOptConstParam { did, const_param_did : Some ( param_did) } )
@@ -60,7 +65,12 @@ pub(crate) fn provide(providers: &mut Providers) {
60
65
optimized_mir_of_const_arg,
61
66
is_mir_available,
62
67
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
+ }
64
74
} ,
65
75
promoted_mir_of_const_arg : |tcx, ( did, param_did) | {
66
76
promoted_mir ( tcx, ty:: WithOptConstParam { did, const_param_did : Some ( param_did) } )
@@ -221,12 +231,6 @@ pub fn run_passes(
221
231
}
222
232
223
233
fn 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
-
230
234
let const_kind = tcx. hir ( ) . body_const_context ( def. did ) ;
231
235
232
236
// No need to const-check a non-const `fn`.
@@ -266,10 +270,8 @@ fn mir_const<'tcx>(
266
270
tcx : TyCtxt < ' tcx > ,
267
271
def : ty:: WithOptConstParam < LocalDefId > ,
268
272
) -> & ' 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) ;
273
275
}
274
276
275
277
// Unsafety check uses the raw mir, so make sure it is run.
@@ -312,10 +314,8 @@ fn mir_validated(
312
314
tcx : TyCtxt < ' tcx > ,
313
315
def : ty:: WithOptConstParam < LocalDefId > ,
314
316
) -> ( & ' 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) ;
319
319
}
320
320
321
321
// Ensure that we compute the `mir_const_qualif` for constants at
@@ -357,13 +357,8 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
357
357
tcx : TyCtxt < ' tcx > ,
358
358
def : ty:: WithOptConstParam < LocalDefId > ,
359
359
) -> & ' 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) ;
367
362
}
368
363
369
364
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
@@ -490,8 +485,8 @@ fn run_optimization_passes<'tcx>(
490
485
491
486
fn optimized_mir < ' tcx > ( tcx : TyCtxt < ' tcx > , did : DefId ) -> & ' tcx Body < ' tcx > {
492
487
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 )
495
490
} else {
496
491
tcx. arena . alloc ( inner_optimized_mir ( tcx, ty:: WithOptConstParam :: unknown ( did) ) )
497
492
}
@@ -528,12 +523,6 @@ fn promoted_mir<'tcx>(
528
523
tcx : TyCtxt < ' tcx > ,
529
524
def : ty:: WithOptConstParam < LocalDefId > ,
530
525
) -> & ' 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
-
537
526
if tcx. is_constructor ( def. did . to_def_id ( ) ) {
538
527
return tcx. arena . alloc ( IndexVec :: new ( ) ) ;
539
528
}
0 commit comments