55//! This also includes code for pattern bindings in `let` statements and
66//! function parameters.
77
8+ use crate :: build:: expr:: as_place:: PlaceBuilder ;
9+ use crate :: build:: scope:: DropKind ;
10+ use crate :: build:: ForGuard :: { self , OutsideGuard , RefWithinGuard } ;
11+ use crate :: build:: {
12+ coverageinfo, BlockAnd , BlockAndExtension , Builder , GuardFrame , GuardFrameLocal , LocalsForNode ,
13+ } ;
14+
815use rustc_data_structures:: fx:: FxIndexMap ;
916use rustc_data_structures:: stack:: ensure_sufficient_stack;
1017use rustc_hir:: { BindingMode , ByRef } ;
@@ -18,12 +25,6 @@ use rustc_span::{BytePos, Pos, Span};
1825use rustc_target:: abi:: VariantIdx ;
1926use tracing:: { debug, instrument} ;
2027
21- use crate :: build:: ForGuard :: { self , OutsideGuard , RefWithinGuard } ;
22- use crate :: build:: expr:: as_place:: PlaceBuilder ;
23- use crate :: build:: scope:: DropKind ;
24- use crate :: build:: {
25- BlockAnd , BlockAndExtension , Builder , GuardFrame , GuardFrameLocal , LocalsForNode , coverageinfo,
26- } ;
2728
2829// helper functions, broken out by category:
2930mod match_pair;
@@ -453,8 +454,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
453454 opt_scrutinee_place,
454455 ) ;
455456
456- // FIXME: Propagate this info down to codegen
457- let pre_binding_block = branch. sub_branches [ 0 ] . otherwise_block ;
457+ let sub_branches: Vec < _ > = branch
458+ . sub_branches
459+ . iter ( )
460+ . map ( |b| coverageinfo:: MatchArmSubBranch {
461+ source_info : this. source_info ( b. span ) ,
462+ start_block : b. start_block ,
463+ } )
464+ . collect ( ) ;
458465
459466 let arm_block = this. bind_pattern (
460467 outer_source_info,
@@ -468,7 +475,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
468475 if let Some ( coverage_match_arms) = coverage_match_arms. as_mut ( ) {
469476 coverage_match_arms. push ( coverageinfo:: MatchArm {
470477 source_info : this. source_info ( arm. pattern . span ) ,
471- pre_binding_block : Some ( pre_binding_block ) ,
478+ sub_branches ,
472479 arm_block,
473480 } )
474481 }
@@ -1391,6 +1398,8 @@ pub(crate) struct ArmHasGuard(pub(crate) bool);
13911398#[ derive( Debug ) ]
13921399struct MatchTreeSubBranch < ' tcx > {
13931400 span : Span ,
1401+ /// The first block in this sub branch.
1402+ start_block : Option < BasicBlock > ,
13941403 /// The block that is branched to if the corresponding subpattern matches.
13951404 success_block : BasicBlock ,
13961405 /// The block to branch to if this arm had a guard and the guard fails.
@@ -1441,6 +1450,7 @@ impl<'tcx> MatchTreeSubBranch<'tcx> {
14411450 debug_assert ! ( candidate. match_pairs. is_empty( ) ) ;
14421451 MatchTreeSubBranch {
14431452 span : candidate. extra_data . span ,
1453+ start_block : candidate. false_edge_start_block ,
14441454 success_block : candidate. pre_binding_block . unwrap ( ) ,
14451455 otherwise_block : candidate. otherwise_block . unwrap ( ) ,
14461456 bindings : parent_data
@@ -1860,7 +1870,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18601870 } ) ;
18611871 for candidate in candidates_to_expand. iter_mut ( ) {
18621872 if !candidate. subcandidates . is_empty ( ) {
1863- self . merge_trivial_subcandidates ( candidate) ;
1873+ // FIXME: Support merging trival candidates in branch coverage instrumentation
1874+ if self . coverage_info . is_none ( ) {
1875+ self . merge_trivial_subcandidates ( candidate) ;
1876+ }
18641877 self . remove_never_subcandidates ( candidate) ;
18651878 }
18661879 }
0 commit comments