@@ -474,7 +474,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
474
474
// candidate.
475
475
self . bind_and_guard_matched_candidate (
476
476
candidate,
477
- & [ ] ,
477
+ & mut vec ! [ ] ,
478
478
fake_borrow_temps,
479
479
scrutinee_span,
480
480
arm_match_scope,
@@ -505,13 +505,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
505
505
traverse_candidate (
506
506
candidate,
507
507
& mut Vec :: new ( ) ,
508
- & mut |leaf_candidate, parent_data | {
508
+ & mut |leaf_candidate, collected_data | {
509
509
if let Some ( arm) = arm {
510
510
self . clear_top_scope ( arm. scope ) ;
511
511
}
512
512
let binding_end = self . bind_and_guard_matched_candidate (
513
513
leaf_candidate,
514
- parent_data ,
514
+ collected_data ,
515
515
fake_borrow_temps,
516
516
scrutinee_span,
517
517
arm_match_scope,
@@ -523,12 +523,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
523
523
}
524
524
self . cfg . goto ( binding_end, outer_source_info, target_block) ;
525
525
} ,
526
- |inner_candidate, parent_data | {
527
- parent_data . push ( inner_candidate. extra_data ) ;
526
+ |inner_candidate, collected_data | {
527
+ collected_data . push ( inner_candidate. extra_data ) ;
528
528
inner_candidate. subcandidates . into_iter ( )
529
529
} ,
530
- |parent_data | {
531
- parent_data . pop ( ) ;
530
+ |collected_data | {
531
+ collected_data . pop ( ) ;
532
532
} ,
533
533
) ;
534
534
@@ -929,7 +929,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
929
929
930
930
/// Data extracted from a pattern that doesn't affect which branch is taken. Collected during
931
931
/// pattern simplification and not mutated later.
932
- #[ derive( Debug , Clone ) ]
932
+ #[ derive( Debug , Clone , Default ) ]
933
933
struct PatternExtraData < ' tcx > {
934
934
/// [`Span`] of the original pattern.
935
935
span : Span ,
@@ -1958,7 +1958,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1958
1958
fn bind_and_guard_matched_candidate < ' pat > (
1959
1959
& mut self ,
1960
1960
candidate : Candidate < ' pat , ' tcx > ,
1961
- parent_data : & [ PatternExtraData < ' tcx > ] ,
1961
+ // Manage in a stack fashion.
1962
+ collected_data : & mut Vec < PatternExtraData < ' tcx > > ,
1962
1963
fake_borrows : & [ ( Place < ' tcx > , Local ) ] ,
1963
1964
scrutinee_span : Span ,
1964
1965
arm_match_scope : Option < ( & Arm < ' tcx > , region:: Scope ) > ,
@@ -1970,6 +1971,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1970
1971
debug_assert ! ( candidate. match_pairs. is_empty( ) ) ;
1971
1972
1972
1973
let candidate_source_info = self . source_info ( candidate. extra_data . span ) ;
1974
+ collected_data. push ( candidate. extra_data ) ;
1973
1975
1974
1976
let mut block = candidate. pre_binding_block . unwrap ( ) ;
1975
1977
@@ -1984,14 +1986,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1984
1986
block = fresh_block;
1985
1987
}
1986
1988
1987
- self . ascribe_types (
1988
- block,
1989
- parent_data
1990
- . iter ( )
1991
- . flat_map ( |d| & d. ascriptions )
1992
- . cloned ( )
1993
- . chain ( candidate. extra_data . ascriptions ) ,
1994
- ) ;
1989
+ self . ascribe_types ( block, collected_data. iter ( ) . flat_map ( |d| & d. ascriptions ) . cloned ( ) ) ;
1995
1990
1996
1991
// rust-lang/rust#27282: The `autoref` business deserves some
1997
1992
// explanation here.
@@ -2074,12 +2069,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2074
2069
// the reference that we create for the arm.
2075
2070
// * So we eagerly create the reference for the arm and then take a
2076
2071
// reference to that.
2077
- if let Some ( ( arm, match_scope) ) = arm_match_scope
2072
+ let block = if let Some ( ( arm, match_scope) ) = arm_match_scope
2078
2073
&& let Some ( guard) = arm. guard
2079
2074
{
2080
2075
let tcx = self . tcx ;
2081
- let bindings =
2082
- parent_data. iter ( ) . flat_map ( |d| & d. bindings ) . chain ( & candidate. extra_data . bindings ) ;
2076
+ let bindings = collected_data. iter ( ) . flat_map ( |d| & d. bindings ) ;
2083
2077
2084
2078
self . bind_matched_candidate_for_guard ( block, schedule_drops, bindings. clone ( ) ) ;
2085
2079
let guard_frame = GuardFrame {
@@ -2157,10 +2151,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2157
2151
// ```
2158
2152
//
2159
2153
// and that is clearly not correct.
2160
- let by_value_bindings = parent_data
2154
+ let by_value_bindings = collected_data
2161
2155
. iter ( )
2162
2156
. flat_map ( |d| & d. bindings )
2163
- . chain ( & candidate. extra_data . bindings )
2164
2157
. filter ( |binding| matches ! ( binding. binding_mode, BindingMode :: ByValue ) ) ;
2165
2158
// Read all of the by reference bindings to ensure that the
2166
2159
// place they refer to can't be modified by the guard.
@@ -2185,11 +2178,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2185
2178
self . bind_matched_candidate_for_arm_body (
2186
2179
block,
2187
2180
schedule_drops,
2188
- parent_data . iter ( ) . flat_map ( |d| & d. bindings ) . chain ( & candidate . extra_data . bindings ) ,
2181
+ collected_data . iter ( ) . flat_map ( |d| & d. bindings ) ,
2189
2182
storages_alive,
2190
2183
) ;
2191
2184
block
2192
- }
2185
+ } ;
2186
+ collected_data. pop ( ) ;
2187
+ block
2193
2188
}
2194
2189
2195
2190
/// Append `AscribeUserType` statements onto the end of `block`
0 commit comments