Skip to content

Commit 9601c58

Browse files
committed
Bug fixes for or-patterns in match statement coverage
1 parent 8ef1d08 commit 9601c58

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

compiler/rustc_mir_build/src/build/coverageinfo.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ struct NotInfo {
4646
pub(crate) struct MatchArm {
4747
pub(crate) source_info: SourceInfo,
4848
pub(crate) sub_branches: Vec<MatchArmSubBranch>,
49-
pub(crate) arm_block: BasicBlock,
5049
}
5150

5251
#[derive(Debug)]
5352
pub(crate) struct MatchArmSubBranch {
5453
pub(crate) source_info: SourceInfo,
55-
pub(crate) start_block: Option<BasicBlock>,
54+
pub(crate) block: BasicBlock,
5655
}
5756

5857
#[derive(Default)]
@@ -193,24 +192,24 @@ impl CoverageInfoBuilder {
193192

194193
let branch_arms = arms
195194
.iter()
196-
.flat_map(|MatchArm { source_info, sub_branches, arm_block }| {
197-
let arm_taken_marker =
198-
self.markers.inject_block_marker(cfg, *source_info, *arm_block);
199-
let branch_arms = sub_branches
195+
.flat_map(|MatchArm { source_info, sub_branches }| {
196+
sub_branches
200197
.iter()
201-
.filter_map(|sub_branch| {
202-
let Some(block) = sub_branch.start_block else { return None };
203-
let marker =
198+
.map(|sub_branch| {
199+
let block = sub_branch.block;
200+
201+
let pre_guard_marker =
204202
self.markers.inject_block_marker(cfg, sub_branch.source_info, block);
205-
Some(BranchArm {
203+
let arm_taken_marker =
204+
self.markers.inject_block_marker(cfg, *source_info, block);
205+
206+
BranchArm {
206207
span: sub_branch.source_info.span,
207-
pre_guard_marker: marker,
208+
pre_guard_marker,
208209
arm_taken_marker,
209-
})
210+
}
210211
})
211-
.collect::<Vec<_>>();
212-
213-
branch_arms
212+
.collect::<Vec<_>>()
214213
})
215214
.collect::<Vec<_>>();
216215

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
458458
.iter()
459459
.map(|b| coverageinfo::MatchArmSubBranch {
460460
source_info: this.source_info(b.span),
461-
start_block: b.start_block,
461+
block: b.success_block,
462462
})
463463
.collect();
464464

@@ -475,7 +475,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
475475
coverage_match_arms.push(coverageinfo::MatchArm {
476476
source_info: this.source_info(arm.pattern.span),
477477
sub_branches,
478-
arm_block,
479478
})
480479
}
481480

@@ -1397,8 +1396,6 @@ pub(crate) struct ArmHasGuard(pub(crate) bool);
13971396
#[derive(Debug)]
13981397
struct MatchTreeSubBranch<'tcx> {
13991398
span: Span,
1400-
/// The first block in this sub branch.
1401-
start_block: Option<BasicBlock>,
14021399
/// The block that is branched to if the corresponding subpattern matches.
14031400
success_block: BasicBlock,
14041401
/// The block to branch to if this arm had a guard and the guard fails.
@@ -1449,7 +1446,6 @@ impl<'tcx> MatchTreeSubBranch<'tcx> {
14491446
debug_assert!(candidate.match_pairs.is_empty());
14501447
MatchTreeSubBranch {
14511448
span: candidate.extra_data.span,
1452-
start_block: candidate.false_edge_start_block,
14531449
success_block: candidate.pre_binding_block.unwrap(),
14541450
otherwise_block: candidate.otherwise_block.unwrap(),
14551451
bindings: parent_data

0 commit comments

Comments
 (0)