@@ -129,16 +129,14 @@ impl CoverageSpan {
129
129
/// If the span is part of a macro, and the macro is visible (expands directly to the given
130
130
/// body_span), returns the macro name symbol.
131
131
pub fn visible_macro ( & self , body_span : Span ) -> Option < Symbol > {
132
- if let Some ( current_macro) = self . current_macro ( )
133
- && self
134
- . expn_span
135
- . parent_callsite ( )
136
- . unwrap_or_else ( || bug ! ( "macro must have a parent" ) )
137
- . eq_ctxt ( body_span)
138
- {
139
- return Some ( current_macro) ;
140
- }
141
- None
132
+ let current_macro = self . current_macro ( ) ?;
133
+ let parent_callsite = self . expn_span . parent_callsite ( ) ?;
134
+
135
+ // In addition to matching the context of the body span, the parent callsite
136
+ // must also be the source callsite, i.e. the parent must have no parent.
137
+ let is_visible_macro =
138
+ parent_callsite. parent_callsite ( ) . is_none ( ) && parent_callsite. eq_ctxt ( body_span) ;
139
+ is_visible_macro. then_some ( current_macro)
142
140
}
143
141
144
142
pub fn is_macro_expansion ( & self ) -> bool {
@@ -384,10 +382,10 @@ impl<'a> CoverageSpansGenerator<'a> {
384
382
let split_point_after_macro_bang = self . curr_original_span . lo ( )
385
383
+ BytePos ( visible_macro. as_str ( ) . len ( ) as u32 )
386
384
+ BytePos ( 1 ) ; // add 1 for the `!`
385
+ debug_assert ! ( split_point_after_macro_bang <= curr. span. hi( ) ) ;
387
386
if split_point_after_macro_bang > curr. span . hi ( ) {
388
387
// Something is wrong with the macro name span;
389
- // return now to avoid emitting malformed mappings.
390
- // FIXME(#117788): Track down why this happens.
388
+ // return now to avoid emitting malformed mappings (e.g. #117788).
391
389
return ;
392
390
}
393
391
0 commit comments