11//! Values computed by queries that use MIR.
22
3- use crate :: mir:: { Body , Promoted } ;
3+ use crate :: mir:: { abstract_const , Body , Promoted } ;
44use crate :: ty:: { self , Ty , TyCtxt } ;
55use rustc_data_structures:: fx:: FxHashMap ;
66use rustc_data_structures:: sync:: Lrc ;
7+ use rustc_errors:: ErrorReported ;
78use rustc_hir as hir;
89use rustc_hir:: def_id:: { DefId , LocalDefId } ;
910use rustc_index:: bit_set:: BitMatrix ;
@@ -407,7 +408,12 @@ pub struct CoverageInfo {
407408 pub num_expressions : u32 ,
408409}
409410
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.
410415impl < ' tcx > TyCtxt < ' tcx > {
416+ #[ inline]
411417 pub fn mir_borrowck_opt_const_arg (
412418 self ,
413419 def : ty:: WithOptConstParam < LocalDefId > ,
@@ -419,6 +425,7 @@ impl<'tcx> TyCtxt<'tcx> {
419425 }
420426 }
421427
428+ #[ inline]
422429 pub fn mir_const_qualif_opt_const_arg (
423430 self ,
424431 def : ty:: WithOptConstParam < LocalDefId > ,
@@ -430,7 +437,8 @@ impl<'tcx> TyCtxt<'tcx> {
430437 }
431438 }
432439
433- pub fn promoted_mir_of_opt_const_arg (
440+ #[ inline]
441+ pub fn promoted_mir_opt_const_arg (
434442 self ,
435443 def : ty:: WithOptConstParam < DefId > ,
436444 ) -> & ' tcx IndexVec < Promoted , Body < ' tcx > > {
@@ -440,4 +448,28 @@ impl<'tcx> TyCtxt<'tcx> {
440448 self . promoted_mir ( def. did )
441449 }
442450 }
451+
452+ #[ inline]
453+ pub fn optimized_mir_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_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+ }
443475}
0 commit comments