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 ;
@@ -66,8 +64,7 @@ impl CoverageSpans {
66
64
#[ derive( Debug , Clone ) ]
67
65
struct CoverageSpan {
68
66
pub span : Span ,
69
- pub expn_span : Span ,
70
- pub current_macro_or_none : OnceCell < Option < Symbol > > ,
67
+ pub visible_macro : Option < Symbol > ,
71
68
pub bcb : BasicCoverageBlock ,
72
69
/// List of all the original spans from MIR that have been merged into this
73
70
/// span. Mainly used to precisely skip over gaps when truncating a span.
@@ -77,23 +74,16 @@ struct CoverageSpan {
77
74
78
75
impl CoverageSpan {
79
76
pub fn for_fn_sig ( fn_sig_span : Span ) -> Self {
80
- Self :: new ( fn_sig_span, fn_sig_span , START_BCB , false )
77
+ Self :: new ( fn_sig_span, None , START_BCB , false )
81
78
}
82
79
83
80
pub ( super ) fn new (
84
81
span : Span ,
85
- expn_span : Span ,
82
+ visible_macro : Option < Symbol > ,
86
83
bcb : BasicCoverageBlock ,
87
84
is_closure : bool ,
88
85
) -> Self {
89
- Self {
90
- span,
91
- expn_span,
92
- current_macro_or_none : Default :: default ( ) ,
93
- bcb,
94
- merged_spans : vec ! [ span] ,
95
- is_closure,
96
- }
86
+ Self { span, visible_macro, bcb, merged_spans : vec ! [ span] , is_closure }
97
87
}
98
88
99
89
pub fn merge_from ( & mut self , other : & Self ) {
@@ -118,37 +108,6 @@ impl CoverageSpan {
118
108
pub fn is_in_same_bcb ( & self , other : & Self ) -> bool {
119
109
self . bcb == other. bcb
120
110
}
121
-
122
- /// If the span is part of a macro, returns the macro name symbol.
123
- pub fn current_macro ( & self ) -> Option < Symbol > {
124
- self . current_macro_or_none
125
- . get_or_init ( || {
126
- if let ExpnKind :: Macro ( MacroKind :: Bang , current_macro) =
127
- self . expn_span . ctxt ( ) . outer_expn_data ( ) . kind
128
- {
129
- return Some ( current_macro) ;
130
- }
131
- None
132
- } )
133
- . map ( |symbol| symbol)
134
- }
135
-
136
- /// If the span is part of a macro, and the macro is visible (expands directly to the given
137
- /// body_span), returns the macro name symbol.
138
- pub fn visible_macro ( & self , body_span : Span ) -> Option < Symbol > {
139
- let current_macro = self . current_macro ( ) ?;
140
- let parent_callsite = self . expn_span . parent_callsite ( ) ?;
141
-
142
- // In addition to matching the context of the body span, the parent callsite
143
- // must also be the source callsite, i.e. the parent must have no parent.
144
- let is_visible_macro =
145
- parent_callsite. parent_callsite ( ) . is_none ( ) && parent_callsite. eq_ctxt ( body_span) ;
146
- is_visible_macro. then_some ( current_macro)
147
- }
148
-
149
- pub fn is_macro_expansion ( & self ) -> bool {
150
- self . current_macro ( ) . is_some ( )
151
- }
152
111
}
153
112
154
113
/// Converts the initial set of `CoverageSpan`s (one per MIR `Statement` or `Terminator`) into a
@@ -159,10 +118,6 @@ impl CoverageSpan {
159
118
/// execution
160
119
/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
161
120
struct CoverageSpansGenerator < ' a > {
162
- /// A `Span` covering the function body of the MIR (typically from left curly brace to right
163
- /// curly brace).
164
- body_span : Span ,
165
-
166
121
/// The BasicCoverageBlock Control Flow Graph (BCB CFG).
167
122
basic_coverage_blocks : & ' a CoverageGraph ,
168
123
@@ -239,7 +194,6 @@ impl<'a> CoverageSpansGenerator<'a> {
239
194
) ;
240
195
241
196
let coverage_spans = Self {
242
- body_span : hir_info. body_span ,
243
197
basic_coverage_blocks,
244
198
sorted_spans_iter : sorted_spans. into_iter ( ) ,
245
199
some_curr : None ,
@@ -298,7 +252,7 @@ impl<'a> CoverageSpansGenerator<'a> {
298
252
// **originally** the same as the original span of `prev()`. The original spans
299
253
// reflect their original sort order, and for equal spans, conveys a partial
300
254
// ordering based on CFG dominator priority.
301
- if prev. is_macro_expansion ( ) && curr. is_macro_expansion ( ) {
255
+ if prev. visible_macro . is_some ( ) && curr. visible_macro . is_some ( ) {
302
256
// Macros that expand to include branching (such as
303
257
// `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
304
258
// `trace!()`) typically generate callee spans with identical
@@ -360,12 +314,7 @@ impl<'a> CoverageSpansGenerator<'a> {
360
314
fn maybe_push_macro_name_span ( & mut self ) {
361
315
let curr = self . curr ( ) ;
362
316
363
- let Some ( visible_macro) = curr. visible_macro ( self . body_span ) else { return } ;
364
- if let Some ( prev) = & self . some_prev
365
- && prev. expn_span . eq_ctxt ( curr. expn_span )
366
- {
367
- return ;
368
- }
317
+ let Some ( visible_macro) = curr. visible_macro else { return } ;
369
318
370
319
// The split point is relative to `curr_original_span`,
371
320
// because `curr.span` may have been merged with preceding spans.
0 commit comments