@@ -70,7 +70,6 @@ struct Instrumentor<'a, 'tcx> {
7070 mir_body : & ' a mut mir:: Body < ' tcx > ,
7171 hir_info : ExtractedHirInfo ,
7272 basic_coverage_blocks : CoverageGraph ,
73- coverage_counters : CoverageCounters ,
7473}
7574
7675impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
@@ -80,9 +79,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
8079 debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
8180
8281 let basic_coverage_blocks = CoverageGraph :: from_mir ( mir_body) ;
83- let coverage_counters = CoverageCounters :: new ( & basic_coverage_blocks) ;
8482
85- Self { tcx, mir_body, hir_info, basic_coverage_blocks, coverage_counters }
83+ Self { tcx, mir_body, hir_info, basic_coverage_blocks }
8684 }
8785
8886 fn inject_counters ( & ' a mut self ) {
@@ -103,16 +101,18 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
103101 // and all `Expression` dependencies (operands) are also generated, for any other
104102 // `BasicCoverageBlock`s not already associated with a coverage span.
105103 let bcb_has_coverage_spans = |bcb| coverage_spans. bcb_has_coverage_spans ( bcb) ;
106- self . coverage_counters
107- . make_bcb_counters ( & self . basic_coverage_blocks , bcb_has_coverage_spans) ;
104+ let coverage_counters = CoverageCounters :: make_bcb_counters (
105+ & self . basic_coverage_blocks ,
106+ bcb_has_coverage_spans,
107+ ) ;
108108
109- let mappings = self . create_mappings ( & coverage_spans) ;
110- self . inject_coverage_statements ( bcb_has_coverage_spans) ;
109+ let mappings = self . create_mappings ( & coverage_spans, & coverage_counters ) ;
110+ self . inject_coverage_statements ( bcb_has_coverage_spans, & coverage_counters ) ;
111111
112112 self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
113113 function_source_hash : self . hir_info . function_source_hash ,
114- num_counters : self . coverage_counters . num_counters ( ) ,
115- expressions : self . coverage_counters . take_expressions ( ) ,
114+ num_counters : coverage_counters. num_counters ( ) ,
115+ expressions : coverage_counters. into_expressions ( ) ,
116116 mappings,
117117 } ) ) ;
118118 }
@@ -122,7 +122,11 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
122122 ///
123123 /// Precondition: All BCBs corresponding to those spans have been given
124124 /// coverage counters.
125- fn create_mappings ( & self , coverage_spans : & CoverageSpans ) -> Vec < Mapping > {
125+ fn create_mappings (
126+ & self ,
127+ coverage_spans : & CoverageSpans ,
128+ coverage_counters : & CoverageCounters ,
129+ ) -> Vec < Mapping > {
126130 let source_map = self . tcx . sess . source_map ( ) ;
127131 let body_span = self . hir_info . body_span ;
128132
@@ -135,8 +139,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
135139 . bcbs_with_coverage_spans ( )
136140 // For each BCB with spans, get a coverage term for its counter.
137141 . map ( |( bcb, spans) | {
138- let term = self
139- . coverage_counters
142+ let term = coverage_counters
140143 . bcb_counter ( bcb)
141144 . expect ( "all BCBs with spans were given counters" )
142145 . as_term ( ) ;
@@ -157,9 +160,10 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
157160 fn inject_coverage_statements (
158161 & mut self ,
159162 bcb_has_coverage_spans : impl Fn ( BasicCoverageBlock ) -> bool ,
163+ coverage_counters : & CoverageCounters ,
160164 ) {
161165 // Process the counters associated with BCB nodes.
162- for ( bcb, counter_kind) in self . coverage_counters . bcb_node_counters ( ) {
166+ for ( bcb, counter_kind) in coverage_counters. bcb_node_counters ( ) {
163167 let do_inject = match counter_kind {
164168 // Counter-increment statements always need to be injected.
165169 BcbCounter :: Counter { .. } => true ,
@@ -178,7 +182,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
178182 }
179183
180184 // Process the counters associated with BCB edges.
181- for ( from_bcb, to_bcb, counter_kind) in self . coverage_counters . bcb_edge_counters ( ) {
185+ for ( from_bcb, to_bcb, counter_kind) in coverage_counters. bcb_edge_counters ( ) {
182186 let do_inject = match counter_kind {
183187 // Counter-increment statements always need to be injected.
184188 BcbCounter :: Counter { .. } => true ,
0 commit comments