@@ -2436,9 +2436,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24362436 // Lower an instance of the arm guard (if present) for this candidate,
24372437 // and then perform bindings for the arm body.
24382438 if let Some ( ( arm, match_scope) ) = arm_match_scope
2439- && let Some ( guard) = arm. guard
24402439 {
24412440 let tcx = self . tcx ;
2441+
2442+ let mut guards = sub_branch. guard_patterns ;
2443+ if let Some ( guard) = arm. guard {
2444+ guards. push ( guard) ;
2445+ } ;
2446+
2447+ if guards. is_empty ( ) {
2448+ self . bind_matched_candidate_for_arm_body (
2449+ block,
2450+ schedule_drops,
2451+ sub_branch. bindings . iter ( ) ,
2452+ ) ;
2453+
2454+ return block
2455+ } ;
24422456
24432457 // Bindings for guards require some extra handling to automatically
24442458 // insert implicit references/dereferences.
@@ -2465,14 +2479,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24652479
24662480 let ( post_guard_block, otherwise_post_guard_block) =
24672481 self . in_if_then_scope ( match_scope, guard_span, |this| {
2468- guard_span = this. thir [ guard] . span ;
2469- this. then_else_break (
2470- block,
2471- guard,
2472- None , // Use `self.local_scope()` as the temp scope
2473- this. source_info ( arm. span ) ,
2474- DeclareLetBindings :: No , // For guards, `let` bindings are declared separately
2475- )
2482+ guards. into_iter ( ) . fold ( BlockAnd ( block, ( ) ) , |block, guard| {
2483+ guard_span = this. thir [ guard] . span ;
2484+ this. then_else_break (
2485+ block. 0 ,
2486+ guard,
2487+ None , // Use `self.local_scope()` as the temp scope
2488+ this. source_info ( arm. span ) ,
2489+ DeclareLetBindings :: No , // For guards, `let` bindings are declared separately
2490+ )
2491+ } )
24762492 } ) ;
24772493
24782494 // If this isn't the final sub-branch being lowered, we need to unschedule drops of
0 commit comments