@@ -102,13 +102,6 @@ impl CurrCovspan {
102102 let Self { span, bcb, is_closure } = self ;
103103 PrevCovspan { span, bcb, merged_spans : vec ! [ span] , is_closure }
104104 }
105-
106- fn into_refined ( self ) -> RefinedCovspan {
107- // This is only called in cases where `curr` is a closure span that has
108- // been carved out of `prev`.
109- debug_assert ! ( self . is_closure) ;
110- self . into_prev ( ) . into_refined ( )
111- }
112105}
113106
114107#[ derive( Debug ) ]
@@ -138,15 +131,15 @@ impl PrevCovspan {
138131 self . span = self . span . with_hi ( max_hi) ;
139132 }
140133
141- if self . merged_spans . is_empty ( ) { None } else { Some ( self . into_refined ( ) ) }
134+ if self . merged_spans . is_empty ( ) { None } else { self . into_refined ( ) }
142135 }
143136
144- fn refined_copy ( & self ) -> RefinedCovspan {
137+ fn refined_copy ( & self ) -> Option < RefinedCovspan > {
145138 let & Self { span, bcb, merged_spans : _, is_closure } = self ;
146- RefinedCovspan { span, bcb, is_closure }
139+ ( !is_closure ) . then_some ( RefinedCovspan { span, bcb } )
147140 }
148141
149- fn into_refined ( self ) -> RefinedCovspan {
142+ fn into_refined ( self ) -> Option < RefinedCovspan > {
150143 // Even though we consume self, we can just reuse the copying impl.
151144 self . refined_copy ( )
152145 }
@@ -156,7 +149,6 @@ impl PrevCovspan {
156149struct RefinedCovspan {
157150 span : Span ,
158151 bcb : BasicCoverageBlock ,
159- is_closure : bool ,
160152}
161153
162154/// Converts the initial set of coverage spans (one per MIR `Statement` or `Terminator`) into a
@@ -225,7 +217,7 @@ impl SpansRefiner {
225217 " different bcbs and disjoint spans, so keep curr for next iter, and add prev={prev:?}" ,
226218 ) ;
227219 let prev = self . take_prev ( ) . into_refined ( ) ;
228- self . refined_spans . push ( prev) ;
220+ self . refined_spans . extend ( prev) ;
229221 } else if prev. is_closure {
230222 // drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
231223 // next iter
@@ -244,13 +236,9 @@ impl SpansRefiner {
244236 // so add it to the output as well.
245237 if let Some ( prev) = self . some_prev . take ( ) {
246238 debug ! ( " AT END, adding last prev={prev:?}" ) ;
247- self . refined_spans . push ( prev. into_refined ( ) ) ;
239+ self . refined_spans . extend ( prev. into_refined ( ) ) ;
248240 }
249241
250- // Remove spans derived from closures, originally added to ensure the coverage
251- // regions for the current function leave room for the closure's own coverage regions
252- // (injected separately, from the closure's own MIR).
253- self . refined_spans . retain ( |covspan| !covspan. is_closure ) ;
254242 self . refined_spans
255243 }
256244
@@ -313,14 +301,15 @@ impl SpansRefiner {
313301 fn carve_out_span_for_closure ( & mut self ) {
314302 let prev = self . prev ( ) ;
315303 let curr = self . curr ( ) ;
304+ assert ! ( !prev. is_closure && curr. is_closure) ;
316305
317306 let left_cutoff = curr. span . lo ( ) ;
318307 let right_cutoff = curr. span . hi ( ) ;
319308 let has_pre_closure_span = prev. span . lo ( ) < right_cutoff;
320309 let has_post_closure_span = prev. span . hi ( ) > right_cutoff;
321310
322311 if has_pre_closure_span {
323- let mut pre_closure = self . prev ( ) . refined_copy ( ) ;
312+ let mut pre_closure = prev. refined_copy ( ) . expect ( "prev is not a closure span" ) ;
324313 pre_closure. span = pre_closure. span . with_hi ( left_cutoff) ;
325314 debug ! ( " prev overlaps a closure. Adding span for pre_closure={:?}" , pre_closure) ;
326315 self . refined_spans . push ( pre_closure) ;
@@ -331,9 +320,9 @@ impl SpansRefiner {
331320 self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
332321 debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev( ) ) ;
333322
334- // Prevent this curr from becoming prev .
335- let closure_covspan = self . take_curr ( ) . into_refined ( ) ;
336- self . refined_spans . push ( closure_covspan ) ; // since self.prev() was already updated
323+ // Discard this curr, since it's a closure span .
324+ let curr = self . take_curr ( ) ;
325+ assert ! ( curr . is_closure ) ;
337326 }
338327 }
339328
0 commit comments