1- use std:: cell:: OnceCell ;
2-
31use rustc_data_structures:: graph:: WithNumNodes ;
42use rustc_index:: IndexVec ;
53use rustc_middle:: mir;
6- use rustc_span:: { BytePos , ExpnKind , MacroKind , Span , Symbol , DUMMY_SP } ;
4+ use rustc_span:: { BytePos , Span , Symbol , DUMMY_SP } ;
75
86use super :: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
97use crate :: coverage:: ExtractedHirInfo ;
@@ -71,8 +69,7 @@ impl CoverageSpans {
7169#[ derive( Debug , Clone ) ]
7270struct CoverageSpan {
7371 pub span : Span ,
74- pub expn_span : Span ,
75- pub current_macro_or_none : OnceCell < Option < Symbol > > ,
72+ pub visible_macro : Option < Symbol > ,
7673 pub bcb : BasicCoverageBlock ,
7774 /// List of all the original spans from MIR that have been merged into this
7875 /// span. Mainly used to precisely skip over gaps when truncating a span.
@@ -82,23 +79,16 @@ struct CoverageSpan {
8279
8380impl CoverageSpan {
8481 pub fn for_fn_sig ( fn_sig_span : Span ) -> Self {
85- Self :: new ( fn_sig_span, fn_sig_span , START_BCB , false )
82+ Self :: new ( fn_sig_span, None , START_BCB , false )
8683 }
8784
8885 pub ( super ) fn new (
8986 span : Span ,
90- expn_span : Span ,
87+ visible_macro : Option < Symbol > ,
9188 bcb : BasicCoverageBlock ,
9289 is_closure : bool ,
9390 ) -> Self {
94- Self {
95- span,
96- expn_span,
97- current_macro_or_none : Default :: default ( ) ,
98- bcb,
99- merged_spans : vec ! [ span] ,
100- is_closure,
101- }
91+ Self { span, visible_macro, bcb, merged_spans : vec ! [ span] , is_closure }
10292 }
10393
10494 pub fn merge_from ( & mut self , other : & Self ) {
@@ -123,37 +113,6 @@ impl CoverageSpan {
123113 pub fn is_in_same_bcb ( & self , other : & Self ) -> bool {
124114 self . bcb == other. bcb
125115 }
126-
127- /// If the span is part of a macro, returns the macro name symbol.
128- pub fn current_macro ( & self ) -> Option < Symbol > {
129- self . current_macro_or_none
130- . get_or_init ( || {
131- if let ExpnKind :: Macro ( MacroKind :: Bang , current_macro) =
132- self . expn_span . ctxt ( ) . outer_expn_data ( ) . kind
133- {
134- return Some ( current_macro) ;
135- }
136- None
137- } )
138- . map ( |symbol| symbol)
139- }
140-
141- /// If the span is part of a macro, and the macro is visible (expands directly to the given
142- /// body_span), returns the macro name symbol.
143- pub fn visible_macro ( & self , body_span : Span ) -> Option < Symbol > {
144- let current_macro = self . current_macro ( ) ?;
145- let parent_callsite = self . expn_span . parent_callsite ( ) ?;
146-
147- // In addition to matching the context of the body span, the parent callsite
148- // must also be the source callsite, i.e. the parent must have no parent.
149- let is_visible_macro =
150- parent_callsite. parent_callsite ( ) . is_none ( ) && parent_callsite. eq_ctxt ( body_span) ;
151- is_visible_macro. then_some ( current_macro)
152- }
153-
154- pub fn is_macro_expansion ( & self ) -> bool {
155- self . current_macro ( ) . is_some ( )
156- }
157116}
158117
159118/// Converts the initial set of `CoverageSpan`s (one per MIR `Statement` or `Terminator`) into a
@@ -164,10 +123,6 @@ impl CoverageSpan {
164123/// execution
165124/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
166125struct CoverageSpansGenerator < ' a > {
167- /// A `Span` covering the function body of the MIR (typically from left curly brace to right
168- /// curly brace).
169- body_span : Span ,
170-
171126 /// The BasicCoverageBlock Control Flow Graph (BCB CFG).
172127 basic_coverage_blocks : & ' a CoverageGraph ,
173128
@@ -244,7 +199,6 @@ impl<'a> CoverageSpansGenerator<'a> {
244199 ) ;
245200
246201 let coverage_spans = Self {
247- body_span : hir_info. body_span ,
248202 basic_coverage_blocks,
249203 sorted_spans_iter : sorted_spans. into_iter ( ) ,
250204 some_curr : None ,
@@ -303,7 +257,7 @@ impl<'a> CoverageSpansGenerator<'a> {
303257 // **originally** the same as the original span of `prev()`. The original spans
304258 // reflect their original sort order, and for equal spans, conveys a partial
305259 // ordering based on CFG dominator priority.
306- if prev. is_macro_expansion ( ) && curr. is_macro_expansion ( ) {
260+ if prev. visible_macro . is_some ( ) && curr. visible_macro . is_some ( ) {
307261 // Macros that expand to include branching (such as
308262 // `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
309263 // `trace!()`) typically generate callee spans with identical
@@ -365,12 +319,7 @@ impl<'a> CoverageSpansGenerator<'a> {
365319 fn maybe_push_macro_name_span ( & mut self ) {
366320 let curr = self . curr ( ) ;
367321
368- let Some ( visible_macro) = curr. visible_macro ( self . body_span ) else { return } ;
369- if let Some ( prev) = & self . some_prev
370- && prev. expn_span . eq_ctxt ( curr. expn_span )
371- {
372- return ;
373- }
322+ let Some ( visible_macro) = curr. visible_macro else { return } ;
374323
375324 // The split point is relative to `curr_original_span`,
376325 // because `curr.span` may have been merged with preceding spans.
0 commit comments