Change:
Between nightly versions 2022-01-14 and 2022-01-15, 0.8.2 lost track of 82% of the coverage of when using the LLVM coverage option (). Other projects of mine continue to have code coverage correctly measured. I'm not where to start narrowing this down, as I'm not getting any errors or warnings printed. Here are the steps to get good code coverage reports out of 2022-01-14: If you look at the report in the coverage folder, the html report will show 80% coverage. Now, test with the next nightly: If you look at the report again, the html report now shows < 1% coverage. The quantity of profraw files are the same, and the sizes of the files are more or less equivalent. I'm not quite sure where to start narrowing this down since it's a unique issue to this project of mine -- but the only unique part I'm aware of is its size :sweat_smile:. For now I'll pin our CI to the last working nightly. Thank you in advance for any suggestions or help!
We noticed the same when upgrading rustc in our project from (December) to . Code coverage measured with and inexplicably dropped . Some crates that are clearly running don't show up at all in the reports. suggests that this is probably caused by
^ says is also affected.
cc label +requires-nightly +A-code-coverage
Thanks for the report! I've tried reproducing locally and I'm able to see the same behavior. Running the LLVM tools directly, I see this when trying to process coverage data for the various binaries: which seems to be the same issue as was reported in a comment on . I'm continuing to investigate ...
The minimal repro seems to be I think I'll have a fix for this within the next few days.

Discussion:
use rustc_hir::def::DefKind; use rustc_hir::def_id::DefIdSet; use rustc_llvm::RustString; <ins> use rustc_middle::bug; </ins> use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::coverage::CodeRegion; use rustc_middle::ty::TyCtxt;

let coverage_mapping_buffer = llvm::build_byte_buffer(|coverage_mapping_buffer| { mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer); }); <del> debug_assert!( !coverage_mapping_buffer.is_empty(), "Every `FunctionCoverage` should have at least one counter" ); </del> <ins> if coverage_mapping_buffer.is_empty() { if function_coverage.is_used() { bug!( "A used function should have had coverage mapping data but did not: {}", mangled_function_name ); } else { debug!("unused function had no coverage mapping data: {}", mangled_function_name); continue; } } </ins> function_data.push((mangled_function_name, source_hash, is_used, coverage_mapping_buffer)); }

<ins> 1|       |// Regression test for #93054: Functions using uninhabited types often only have a single, 2|       |// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail. 3|       |// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them. 4|       | 5|       |// compile-flags: --edition=2021 6|       | 7|       |enum Never { } 8|       | 9|       |impl Never { 10|       |    fn foo(self) { 11|       |        match self { } 12|       |        make().map(|never| match never { }); 13|       |    } 14|       | 15|       |    fn bar(&self) { 16|       |        match *self { } 17|       |    } 18|       |} 19|       | 20|      0|async fn foo2(never: Never) { 21|       |    match never { } 22|       |} 23|       | 24|      0|fn make() -> Option<Never> { 25|      0|    None 26|      0|} 27|       | 28|      1|fn main() { } </ins>

<ins> // Regression test for #93054: Functions using uninhabited types often only have a single, // unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail. // Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them. // compile-flags: --edition=2021 enum Never { } impl Never { fn foo(self) { match self { } make().map(|never| match never { }); } fn bar(&self) { match *self { } } } async fn foo2(never: Never) { match never { } } fn make() -> Option<Never> { None } fn main() { } </ins>