Skip to content

Commit f758844

Browse files
committed
Avoid adding duplicate coverage markers for match guards
1 parent c3a1fc9 commit f758844

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler/rustc_mir_build/src/build/coverageinfo.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ impl CoverageInfoBuilder {
168168
// Bail out if branch coverage is not enabled.
169169
let Some(branch_info) = self.branch_info.as_mut() else { return };
170170

171+
172+
// Avoid duplicates coverage markers.
173+
// When lowering match sub-branches (like or-patterns), `if` guards will
174+
// be added multiple times for each sub-branch
175+
// FIXME: This feels dirty. It would be nice to find a smarter way to avoid duplicate
176+
// coverage markers.
177+
for arms in &branch_info.branch_arm_lists {
178+
for arm in arms {
179+
if arm.span == source_info.span {
180+
return;
181+
}
182+
}
183+
}
184+
171185
let true_marker = self.markers.inject_block_marker(cfg, source_info, true_block);
172186
let false_marker = self.markers.inject_block_marker(cfg, source_info, false_block);
173187

0 commit comments

Comments
 (0)