1
- use std:: cell:: OnceCell ;
2
-
3
1
use rustc_data_structures:: graph:: WithNumNodes ;
4
2
use rustc_index:: IndexVec ;
5
3
use rustc_middle:: mir;
6
- use rustc_span:: { BytePos , ExpnKind , MacroKind , Span , Symbol , DUMMY_SP } ;
4
+ use rustc_span:: { BytePos , Span , Symbol , DUMMY_SP } ;
7
5
8
6
use super :: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
9
7
use crate :: coverage:: ExtractedHirInfo ;
@@ -71,8 +69,7 @@ impl CoverageSpans {
71
69
#[ derive( Debug , Clone ) ]
72
70
struct CoverageSpan {
73
71
pub span : Span ,
74
- pub expn_span : Span ,
75
- pub current_macro_or_none : OnceCell < Option < Symbol > > ,
72
+ pub visible_macro : Option < Symbol > ,
76
73
pub bcb : BasicCoverageBlock ,
77
74
/// List of all the original spans from MIR that have been merged into this
78
75
/// span. Mainly used to precisely skip over gaps when truncating a span.
@@ -82,23 +79,16 @@ struct CoverageSpan {
82
79
83
80
impl CoverageSpan {
84
81
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 )
86
83
}
87
84
88
85
pub ( super ) fn new (
89
86
span : Span ,
90
- expn_span : Span ,
87
+ visible_macro : Option < Symbol > ,
91
88
bcb : BasicCoverageBlock ,
92
89
is_closure : bool ,
93
90
) -> 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 }
102
92
}
103
93
104
94
pub fn merge_from ( & mut self , other : & Self ) {
@@ -123,37 +113,6 @@ impl CoverageSpan {
123
113
pub fn is_in_same_bcb ( & self , other : & Self ) -> bool {
124
114
self . bcb == other. bcb
125
115
}
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
- }
157
116
}
158
117
159
118
/// Converts the initial set of `CoverageSpan`s (one per MIR `Statement` or `Terminator`) into a
@@ -164,10 +123,6 @@ impl CoverageSpan {
164
123
/// execution
165
124
/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
166
125
struct 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
-
171
126
/// The BasicCoverageBlock Control Flow Graph (BCB CFG).
172
127
basic_coverage_blocks : & ' a CoverageGraph ,
173
128
@@ -244,7 +199,6 @@ impl<'a> CoverageSpansGenerator<'a> {
244
199
) ;
245
200
246
201
let coverage_spans = Self {
247
- body_span : hir_info. body_span ,
248
202
basic_coverage_blocks,
249
203
sorted_spans_iter : sorted_spans. into_iter ( ) ,
250
204
some_curr : None ,
@@ -303,7 +257,7 @@ impl<'a> CoverageSpansGenerator<'a> {
303
257
// **originally** the same as the original span of `prev()`. The original spans
304
258
// reflect their original sort order, and for equal spans, conveys a partial
305
259
// 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 ( ) {
307
261
// Macros that expand to include branching (such as
308
262
// `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
309
263
// `trace!()`) typically generate callee spans with identical
@@ -365,12 +319,7 @@ impl<'a> CoverageSpansGenerator<'a> {
365
319
fn maybe_push_macro_name_span ( & mut self ) {
366
320
let curr = self . curr ( ) ;
367
321
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 } ;
374
323
375
324
// The split point is relative to `curr_original_span`,
376
325
// because `curr.span` may have been merged with preceding spans.
0 commit comments