Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ pub(super) fn extract_refined_covspans<'tcx>(
}

// Each pushed covspan should have the same context as the body span.
// If it somehow doesn't, discard the covspan, or panic in debug builds.
// If it somehow doesn't, discard the covspan.
if !body_span.eq_ctxt(covspan_span) {
debug_assert!(
false,
"span context mismatch: body_span={body_span:?}, covspan.span={covspan_span:?}"
);
// FIXME(Zalathar): Investigate how and why this is triggered
// by `tests/coverage/macros/context-mismatch-issue-147339.rs`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so do we need an issue to track it?

return false;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/coverage/macros/context-mismatch-issue-147339.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Function name: context_mismatch_issue_147339::a (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)

Function name: context_mismatch_issue_147339::b (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)

Function name: context_mismatch_issue_147339::c (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)

Function name: context_mismatch_issue_147339::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 14, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 20, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

28 changes: 28 additions & 0 deletions tests/coverage/macros/context-mismatch-issue-147339.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
LL| |//@ edition: 2024
LL| |
LL| |// These nested macro expansions were found to cause span refinement to produce
LL| |// spans with a context that doesn't match the function body span, triggering
LL| |// a defensive check that discards the span.
LL| |//
LL| |// Reported in <https://github.com/rust-lang/rust/issues/147339>.
LL| |
LL| |macro_rules! foo {
LL| | ($($m:ident $($f:ident $v:tt)+),*) => {
LL| | $($(macro_rules! $f { () => { $v } })+)*
LL| 0| $(macro_rules! $m { () => { $(fn $f() -> i32 { $v })+ } })*
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::a
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::b
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::c
------------------
LL| | }
LL| |}
LL| |
LL| |foo!(m a 1 b 2, n c 3);
LL| |m!();
LL| |n!();
LL| |
LL| 1|fn main() {}

20 changes: 20 additions & 0 deletions tests/coverage/macros/context-mismatch-issue-147339.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ edition: 2024

// These nested macro expansions were found to cause span refinement to produce
// spans with a context that doesn't match the function body span, triggering
// a defensive check that discards the span.
//
// Reported in <https://github.com/rust-lang/rust/issues/147339>.

macro_rules! foo {
($($m:ident $($f:ident $v:tt)+),*) => {
$($(macro_rules! $f { () => { $v } })+)*
$(macro_rules! $m { () => { $(fn $f() -> i32 { $v })+ } })*
}
}

foo!(m a 1 b 2, n c 3);
m!();
n!();

fn main() {}
Loading