@@ -4,7 +4,7 @@ use rustc_middle::mir::coverage::*;
4
4
use rustc_middle:: mir:: visit:: Visitor ;
5
5
use rustc_middle:: mir:: { self , Coverage , CoverageInfo , Location } ;
6
6
use rustc_middle:: ty:: query:: Providers ;
7
- use rustc_middle:: ty:: TyCtxt ;
7
+ use rustc_middle:: ty:: { self , TyCtxt } ;
8
8
use rustc_span:: def_id:: DefId ;
9
9
10
10
/// The `query` provider for `CoverageInfo`, requested by `codegen_coverage()` (to inject each
@@ -112,7 +112,7 @@ impl Visitor<'_> for CoverageVisitor {
112
112
}
113
113
114
114
fn coverageinfo_from_mir < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> CoverageInfo {
115
- let mir_body = tcx . optimized_mir ( def_id) ;
115
+ let mir_body = mir_body ( tcx , def_id) ;
116
116
117
117
let mut coverage_visitor = CoverageVisitor {
118
118
// num_counters always has at least the `ZERO` counter.
@@ -129,8 +129,7 @@ fn coverageinfo_from_mir<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> CoverageInfo
129
129
}
130
130
131
131
fn covered_file_name < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Option < Symbol > {
132
- let mir_body = tcx. optimized_mir ( def_id) ;
133
- for bb_data in mir_body. basic_blocks ( ) . iter ( ) {
132
+ for bb_data in mir_body ( tcx, def_id) . basic_blocks ( ) . iter ( ) {
134
133
for statement in bb_data. statements . iter ( ) {
135
134
if let StatementKind :: Coverage ( box ref coverage) = statement. kind {
136
135
if let Some ( code_region) = coverage. code_region . as_ref ( ) {
@@ -142,9 +141,17 @@ fn covered_file_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Symbol> {
142
141
None
143
142
}
144
143
144
+ /// This function ensures we obtain the correct MIR for the given item irrespective of
145
+ /// whether that means const mir or runtime mir. For `const fn` this opts for runtime
146
+ /// mir.
147
+ fn mir_body < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> & ' tcx mir:: Body < ' tcx > {
148
+ let id = ty:: WithOptConstParam :: unknown ( def_id) ;
149
+ let def = ty:: InstanceDef :: Item ( id) ;
150
+ tcx. instance_mir ( def)
151
+ }
152
+
145
153
fn covered_code_regions < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Vec < & ' tcx CodeRegion > {
146
- let mir_body: & ' tcx mir:: Body < ' tcx > = tcx. optimized_mir ( def_id) ;
147
- mir_body
154
+ mir_body ( tcx, def_id)
148
155
. basic_blocks ( )
149
156
. iter ( )
150
157
. map ( |data| {
0 commit comments