@@ -68,41 +68,29 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
68
68
struct Instrumentor < ' a , ' tcx > {
69
69
tcx : TyCtxt < ' tcx > ,
70
70
mir_body : & ' a mut mir:: Body < ' tcx > ,
71
- fn_sig_span : Span ,
72
- body_span : Span ,
73
- function_source_hash : u64 ,
71
+ hir_info : ExtractedHirInfo ,
74
72
basic_coverage_blocks : CoverageGraph ,
75
73
coverage_counters : CoverageCounters ,
76
74
}
77
75
78
76
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
79
77
fn new ( tcx : TyCtxt < ' tcx > , mir_body : & ' a mut mir:: Body < ' tcx > ) -> Self {
80
- let hir_info @ ExtractedHirInfo { function_source_hash, fn_sig_span, body_span } =
81
- extract_hir_info ( tcx, mir_body. source . def_id ( ) . expect_local ( ) ) ;
78
+ let hir_info = extract_hir_info ( tcx, mir_body. source . def_id ( ) . expect_local ( ) ) ;
82
79
83
80
debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
84
81
85
82
let basic_coverage_blocks = CoverageGraph :: from_mir ( mir_body) ;
86
83
let coverage_counters = CoverageCounters :: new ( & basic_coverage_blocks) ;
87
84
88
- Self {
89
- tcx,
90
- mir_body,
91
- fn_sig_span,
92
- body_span,
93
- function_source_hash,
94
- basic_coverage_blocks,
95
- coverage_counters,
96
- }
85
+ Self { tcx, mir_body, hir_info, basic_coverage_blocks, coverage_counters }
97
86
}
98
87
99
88
fn inject_counters ( & ' a mut self ) {
100
89
////////////////////////////////////////////////////
101
90
// Compute coverage spans from the `CoverageGraph`.
102
91
let Some ( coverage_spans) = CoverageSpans :: generate_coverage_spans (
103
92
self . mir_body ,
104
- self . fn_sig_span ,
105
- self . body_span ,
93
+ & self . hir_info ,
106
94
& self . basic_coverage_blocks ,
107
95
) else {
108
96
// No relevant spans were found in MIR, so skip instrumenting this function.
@@ -121,7 +109,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
121
109
let mappings = self . create_mappings_and_inject_coverage_statements ( & coverage_spans) ;
122
110
123
111
self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
124
- function_source_hash : self . function_source_hash ,
112
+ function_source_hash : self . hir_info . function_source_hash ,
125
113
num_counters : self . coverage_counters . num_counters ( ) ,
126
114
expressions : self . coverage_counters . take_expressions ( ) ,
127
115
mappings,
@@ -136,7 +124,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
136
124
coverage_spans : & CoverageSpans ,
137
125
) -> Vec < Mapping > {
138
126
let source_map = self . tcx . sess . source_map ( ) ;
139
- let body_span = self . body_span ;
127
+ let body_span = self . hir_info . body_span ;
140
128
141
129
let source_file = source_map. lookup_source_file ( body_span. lo ( ) ) ;
142
130
use rustc_session:: RemapFileNameExt ;
0 commit comments