@@ -8,34 +8,31 @@ use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
88
99pub ( crate ) struct FunctionCoverage < ' tcx > {
1010 pub ( crate ) function_coverage_info : & ' tcx FunctionCoverageInfo ,
11- ids_info : & ' tcx CoverageIdsInfo ,
12- is_used : bool ,
11+ /// If `None`, the corresponding function is unused.
12+ ids_info : Option < & ' tcx CoverageIdsInfo > ,
1313}
1414
1515impl < ' tcx > FunctionCoverage < ' tcx > {
1616 pub ( crate ) fn new_used (
1717 function_coverage_info : & ' tcx FunctionCoverageInfo ,
1818 ids_info : & ' tcx CoverageIdsInfo ,
1919 ) -> Self {
20- Self { function_coverage_info, ids_info, is_used : true }
20+ Self { function_coverage_info, ids_info : Some ( ids_info ) }
2121 }
2222
23- pub ( crate ) fn new_unused (
24- function_coverage_info : & ' tcx FunctionCoverageInfo ,
25- ids_info : & ' tcx CoverageIdsInfo ,
26- ) -> Self {
27- Self { function_coverage_info, ids_info, is_used : false }
23+ pub ( crate ) fn new_unused ( function_coverage_info : & ' tcx FunctionCoverageInfo ) -> Self {
24+ Self { function_coverage_info, ids_info : None }
2825 }
2926
3027 /// Returns true for a used (called) function, and false for an unused function.
3128 pub ( crate ) fn is_used ( & self ) -> bool {
32- self . is_used
29+ self . ids_info . is_some ( )
3330 }
3431
3532 /// Return the source hash, generated from the HIR node structure, and used to indicate whether
3633 /// or not the source code structure changed between different compilations.
3734 pub ( crate ) fn source_hash ( & self ) -> u64 {
38- if self . is_used { self . function_coverage_info . function_source_hash } else { 0 }
35+ if self . is_used ( ) { self . function_coverage_info . function_source_hash } else { 0 }
3936 }
4037
4138 /// Convert this function's coverage expression data into a form that can be
@@ -78,6 +75,10 @@ impl<'tcx> FunctionCoverage<'tcx> {
7875 }
7976
8077 fn is_zero_term ( & self , term : CovTerm ) -> bool {
81- !self . is_used || self . ids_info . is_zero_term ( term)
78+ match self . ids_info {
79+ Some ( ids_info) => ids_info. is_zero_term ( term) ,
80+ // This function is unused, so all coverage counters/expressions are zero.
81+ None => true ,
82+ }
8283 }
8384}
0 commit comments