@@ -143,19 +143,21 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
143143
144144 let bx = self ;
145145
146+ // Due to LocalCopy instantiation or MIR inlining, coverage statements
147+ // can end up in a crate that isn't doing coverage instrumentation.
148+ // When that happens, we currently just discard those statements, so
149+ // the corresponding code will be undercounted.
150+ // FIXME(Zalathar): Find a better solution for mixed-coverage builds.
151+ let Some ( coverage_cx) = & bx. cx . coverage_cx else { return } ;
152+
146153 let Some ( function_coverage_info) =
147154 bx. tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( )
148155 else {
149156 debug ! ( "function has a coverage statement but no coverage info" ) ;
150157 return ;
151158 } ;
152159
153- // FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
154- // wild, so keep this early-return until we understand why.
155- let mut coverage_map = match bx. coverage_cx {
156- Some ( ref cx) => cx. function_coverage_map . borrow_mut ( ) ,
157- None => return ,
158- } ;
160+ let mut coverage_map = coverage_cx. function_coverage_map . borrow_mut ( ) ;
159161 let func_coverage = coverage_map
160162 . entry ( instance)
161163 . or_insert_with ( || FunctionCoverageCollector :: new ( instance, function_coverage_info) ) ;
@@ -197,18 +199,19 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
197199 }
198200 CoverageKind :: CondBitmapUpdate { index, decision_depth } => {
199201 drop ( coverage_map) ;
200- let cond_bitmap = bx
201- . coverage_cx ( )
202+ let cond_bitmap = coverage_cx
202203 . try_get_mcdc_condition_bitmap ( & instance, decision_depth)
203204 . expect ( "mcdc cond bitmap should have been allocated for updating" ) ;
204205 let cond_index = bx. const_i32 ( index as i32 ) ;
205206 bx. mcdc_condbitmap_update ( cond_index, cond_bitmap) ;
206207 }
207208 CoverageKind :: TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
208209 drop ( coverage_map) ;
209- let cond_bitmap = bx. coverage_cx ( )
210- . try_get_mcdc_condition_bitmap ( & instance, decision_depth)
211- . expect ( "mcdc cond bitmap should have been allocated for merging into the global bitmap" ) ;
210+ let cond_bitmap =
211+ coverage_cx. try_get_mcdc_condition_bitmap ( & instance, decision_depth) . expect (
212+ "mcdc cond bitmap should have been allocated for merging \
213+ into the global bitmap",
214+ ) ;
212215 assert ! (
213216 bitmap_idx as usize <= function_coverage_info. mcdc_bitmap_bits,
214217 "bitmap index of the decision out of range"
0 commit comments