coverage: Be more strict about what counts as a "visible macro"
This commit is contained in:
parent
ff3af59f2b
commit
242bff3cda
1 changed files with 10 additions and 12 deletions
|
@ -129,16 +129,14 @@ impl CoverageSpan {
|
||||||
/// If the span is part of a macro, and the macro is visible (expands directly to the given
|
/// If the span is part of a macro, and the macro is visible (expands directly to the given
|
||||||
/// body_span), returns the macro name symbol.
|
/// body_span), returns the macro name symbol.
|
||||||
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
|
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
|
||||||
if let Some(current_macro) = self.current_macro()
|
let current_macro = self.current_macro()?;
|
||||||
&& self
|
let parent_callsite = self.expn_span.parent_callsite()?;
|
||||||
.expn_span
|
|
||||||
.parent_callsite()
|
// In addition to matching the context of the body span, the parent callsite
|
||||||
.unwrap_or_else(|| bug!("macro must have a parent"))
|
// must also be the source callsite, i.e. the parent must have no parent.
|
||||||
.eq_ctxt(body_span)
|
let is_visible_macro =
|
||||||
{
|
parent_callsite.parent_callsite().is_none() && parent_callsite.eq_ctxt(body_span);
|
||||||
return Some(current_macro);
|
is_visible_macro.then_some(current_macro)
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_macro_expansion(&self) -> bool {
|
pub fn is_macro_expansion(&self) -> bool {
|
||||||
|
@ -384,10 +382,10 @@ impl<'a> CoverageSpansGenerator<'a> {
|
||||||
let split_point_after_macro_bang = self.curr_original_span.lo()
|
let split_point_after_macro_bang = self.curr_original_span.lo()
|
||||||
+ BytePos(visible_macro.as_str().len() as u32)
|
+ BytePos(visible_macro.as_str().len() as u32)
|
||||||
+ BytePos(1); // add 1 for the `!`
|
+ BytePos(1); // add 1 for the `!`
|
||||||
|
debug_assert!(split_point_after_macro_bang <= curr.span.hi());
|
||||||
if split_point_after_macro_bang > curr.span.hi() {
|
if split_point_after_macro_bang > curr.span.hi() {
|
||||||
// Something is wrong with the macro name span;
|
// Something is wrong with the macro name span;
|
||||||
// return now to avoid emitting malformed mappings.
|
// return now to avoid emitting malformed mappings (e.g. #117788).
|
||||||
// FIXME(#117788): Track down why this happens.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue