@@ -95,12 +95,13 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
9595
9696 let coverage_counters = counters:: make_bcb_counters ( & graph, & bcbs_with_counter_mappings) ;
9797
98- let mappings = create_mappings ( & extracted_mappings, & coverage_counters ) ;
98+ let mappings = create_mappings ( & extracted_mappings) ;
9999 if mappings. is_empty ( ) {
100100 // No spans could be converted into valid mappings, so skip this function.
101101 debug ! ( "no spans could be converted into valid mappings; skipping" ) ;
102102 return ;
103103 }
104+ let term_for_bcb = coverage_counters. node_counters . clone ( ) ;
104105
105106 inject_coverage_statements ( mir_body, & graph, & extracted_mappings, & coverage_counters) ;
106107
@@ -116,26 +117,24 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
116117 mir_body. function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
117118 function_source_hash : hir_info. function_source_hash ,
118119 body_span : hir_info. body_span ,
120+
119121 num_counters : coverage_counters. num_counters ( ) ,
120- mcdc_bitmap_bits : extracted_mappings. mcdc_bitmap_bits ,
121122 expressions : coverage_counters. into_expressions ( ) ,
123+
122124 mappings,
125+ term_for_bcb,
126+
127+ mcdc_bitmap_bits : extracted_mappings. mcdc_bitmap_bits ,
123128 mcdc_num_condition_bitmaps,
124129 } ) ) ;
125130}
126131
127- /// For each coverage span extracted from MIR, create a corresponding
128- /// mapping.
132+ /// For each coverage span extracted from MIR, create a corresponding mapping.
129133///
130- /// Precondition: All BCBs corresponding to those spans have been given
131- /// coverage counters.
132- fn create_mappings (
133- extracted_mappings : & ExtractedMappings ,
134- coverage_counters : & CoverageCounters ,
135- ) -> Vec < Mapping > {
136- let term_for_bcb =
137- |bcb| coverage_counters. term_for_bcb ( bcb) . expect ( "all BCBs with spans were given counters" ) ;
138-
134+ /// FIXME(Zalathar): This used to be where BCBs in the extracted mappings were
135+ /// resolved to a `CovTerm`. But that is now handled elsewhere, so this
136+ /// function can potentially be simplified even further.
137+ fn create_mappings ( extracted_mappings : & ExtractedMappings ) -> Vec < Mapping > {
139138 // Fully destructure the mappings struct to make sure we don't miss any kinds.
140139 let ExtractedMappings {
141140 num_bcbs : _,
@@ -150,23 +149,18 @@ fn create_mappings(
150149 mappings. extend ( code_mappings. iter ( ) . map (
151150 // Ordinary code mappings are the simplest kind.
152151 |& mappings:: CodeMapping { span, bcb } | {
153- let kind = MappingKind :: Code ( term_for_bcb ( bcb) ) ;
152+ let kind = MappingKind :: Code { bcb } ;
154153 Mapping { kind, span }
155154 } ,
156155 ) ) ;
157156
158157 mappings. extend ( branch_pairs. iter ( ) . map (
159158 |& mappings:: BranchPair { span, true_bcb, false_bcb } | {
160- let true_term = term_for_bcb ( true_bcb) ;
161- let false_term = term_for_bcb ( false_bcb) ;
162- let kind = MappingKind :: Branch { true_term, false_term } ;
159+ let kind = MappingKind :: Branch { true_bcb, false_bcb } ;
163160 Mapping { kind, span }
164161 } ,
165162 ) ) ;
166163
167- let term_for_bcb =
168- |bcb| coverage_counters. term_for_bcb ( bcb) . expect ( "all BCBs with spans were given counters" ) ;
169-
170164 // MCDC branch mappings are appended with their decisions in case decisions were ignored.
171165 mappings. extend ( mcdc_degraded_branches. iter ( ) . map (
172166 |& mappings:: MCDCBranch {
@@ -176,11 +170,7 @@ fn create_mappings(
176170 condition_info : _,
177171 true_index : _,
178172 false_index : _,
179- } | {
180- let true_term = term_for_bcb ( true_bcb) ;
181- let false_term = term_for_bcb ( false_bcb) ;
182- Mapping { kind : MappingKind :: Branch { true_term, false_term } , span }
183- } ,
173+ } | { Mapping { kind : MappingKind :: Branch { true_bcb, false_bcb } , span } } ,
184174 ) ) ;
185175
186176 for ( decision, branches) in mcdc_mappings {
@@ -201,12 +191,10 @@ fn create_mappings(
201191 true_index : _,
202192 false_index : _,
203193 } | {
204- let true_term = term_for_bcb ( true_bcb) ;
205- let false_term = term_for_bcb ( false_bcb) ;
206194 Mapping {
207195 kind : MappingKind :: MCDCBranch {
208- true_term ,
209- false_term ,
196+ true_bcb ,
197+ false_bcb ,
210198 mcdc_params : condition_info,
211199 } ,
212200 span,
0 commit comments