1
1
//! Values computed by queries that use MIR.
2
2
3
- use crate :: mir:: { Body , Promoted } ;
3
+ use crate :: mir:: { abstract_const , Body , Promoted } ;
4
4
use crate :: ty:: { self , Ty , TyCtxt } ;
5
5
use rustc_data_structures:: fx:: FxHashMap ;
6
6
use rustc_data_structures:: sync:: Lrc ;
7
+ use rustc_errors:: ErrorReported ;
7
8
use rustc_hir as hir;
8
9
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
9
10
use rustc_index:: bit_set:: BitMatrix ;
@@ -407,7 +408,12 @@ pub struct CoverageInfo {
407
408
pub num_expressions : u32 ,
408
409
}
409
410
411
+ /// Shims which make dealing with `WithOptConstParam` easier.
412
+ ///
413
+ /// For more information on why this is needed, consider looking
414
+ /// at the docs for `WithOptConstParam` itself.
410
415
impl < ' tcx > TyCtxt < ' tcx > {
416
+ #[ inline]
411
417
pub fn mir_borrowck_opt_const_arg (
412
418
self ,
413
419
def : ty:: WithOptConstParam < LocalDefId > ,
@@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
419
425
}
420
426
}
421
427
428
+ #[ inline]
422
429
pub fn mir_const_qualif_opt_const_arg (
423
430
self ,
424
431
def : ty:: WithOptConstParam < LocalDefId > ,
@@ -430,6 +437,7 @@ impl<'tcx> TyCtxt<'tcx> {
430
437
}
431
438
}
432
439
440
+ #[ inline]
433
441
pub fn promoted_mir_of_opt_const_arg (
434
442
self ,
435
443
def : ty:: WithOptConstParam < DefId > ,
@@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
440
448
self . promoted_mir ( def. did )
441
449
}
442
450
}
451
+
452
+ #[ inline]
453
+ pub fn optimized_mir_of_opt_const_arg (
454
+ self ,
455
+ def : ty:: WithOptConstParam < DefId > ,
456
+ ) -> & ' tcx Body < ' tcx > {
457
+ if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
458
+ self . optimized_mir_of_const_arg ( ( did, param_did) )
459
+ } else {
460
+ self . optimized_mir ( def. did )
461
+ }
462
+ }
463
+
464
+ #[ inline]
465
+ pub fn mir_abstract_const_of_opt_const_arg (
466
+ self ,
467
+ def : ty:: WithOptConstParam < DefId > ,
468
+ ) -> Result < Option < & ' tcx [ abstract_const:: Node < ' tcx > ] > , ErrorReported > {
469
+ if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
470
+ self . mir_abstract_const_of_const_arg ( ( did, param_did) )
471
+ } else {
472
+ self . mir_abstract_const ( def. did )
473
+ }
474
+ }
443
475
}
0 commit comments