Skip to content

Commit 242bff3

Browse files
committed
coverage: Be more strict about what counts as a "visible macro"
1 parent ff3af59 commit 242bff3

File tree

1 file changed

+10
-12
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+10
-12
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,14 @@ impl CoverageSpan {
129129
/// If the span is part of a macro, and the macro is visible (expands directly to the given
130130
/// body_span), returns the macro name symbol.
131131
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)
142140
}
143141

144142
pub fn is_macro_expansion(&self) -> bool {
@@ -384,10 +382,10 @@ impl<'a> CoverageSpansGenerator<'a> {
384382
let split_point_after_macro_bang = self.curr_original_span.lo()
385383
+ BytePos(visible_macro.as_str().len() as u32)
386384
+ BytePos(1); // add 1 for the `!`
385+
debug_assert!(split_point_after_macro_bang <= curr.span.hi());
387386
if split_point_after_macro_bang > curr.span.hi() {
388387
// 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).
391389
return;
392390
}
393391

0 commit comments

Comments
 (0)