@@ -8,34 +8,31 @@ use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
8
8
9
9
pub ( crate ) struct FunctionCoverage < ' tcx > {
10
10
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 > ,
13
13
}
14
14
15
15
impl < ' tcx > FunctionCoverage < ' tcx > {
16
16
pub ( crate ) fn new_used (
17
17
function_coverage_info : & ' tcx FunctionCoverageInfo ,
18
18
ids_info : & ' tcx CoverageIdsInfo ,
19
19
) -> Self {
20
- Self { function_coverage_info, ids_info, is_used : true }
20
+ Self { function_coverage_info, ids_info : Some ( ids_info ) }
21
21
}
22
22
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 }
28
25
}
29
26
30
27
/// Returns true for a used (called) function, and false for an unused function.
31
28
pub ( crate ) fn is_used ( & self ) -> bool {
32
- self . is_used
29
+ self . ids_info . is_some ( )
33
30
}
34
31
35
32
/// Return the source hash, generated from the HIR node structure, and used to indicate whether
36
33
/// or not the source code structure changed between different compilations.
37
34
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 }
39
36
}
40
37
41
38
/// Convert this function's coverage expression data into a form that can be
@@ -78,6 +75,10 @@ impl<'tcx> FunctionCoverage<'tcx> {
78
75
}
79
76
80
77
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
+ }
82
83
}
83
84
}
0 commit comments