@@ -58,9 +58,9 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
58
58
}
59
59
60
60
let ccx = ConstCx :: new ( tcx, body) ;
61
- let ( mut temps, all_candidates) = collect_temps_and_candidates ( & ccx) ;
61
+ let ( mut temps, mut all_candidates) = collect_temps_and_candidates ( & ccx) ;
62
62
63
- let promotable_candidates = validate_candidates ( & ccx, & mut temps, & all_candidates) ;
63
+ let promotable_candidates = validate_candidates ( & ccx, & mut temps, & mut all_candidates) ;
64
64
65
65
let promoted = promote_candidates ( body, tcx, temps, promotable_candidates) ;
66
66
self . promoted_fragments . set ( promoted) ;
@@ -688,18 +688,15 @@ impl<'tcx> Validator<'_, 'tcx> {
688
688
}
689
689
}
690
690
691
- fn validate_candidates (
691
+ fn validate_candidates < ' a > (
692
692
ccx : & ConstCx < ' _ , ' _ > ,
693
693
temps : & mut IndexSlice < Local , TempState > ,
694
- candidates : & [ Candidate ] ,
695
- ) -> Vec < Candidate > {
694
+ candidates : & ' a mut Vec < Candidate > ,
695
+ ) -> & ' a [ Candidate ] {
696
696
let mut validator = Validator { ccx, temps, promotion_safe_blocks : None } ;
697
697
698
- candidates
699
- . iter ( )
700
- . copied ( )
701
- . filter ( |& candidate| validator. validate_candidate ( candidate) . is_ok ( ) )
702
- . collect ( )
698
+ candidates. retain ( |& candidate| validator. validate_candidate ( candidate) . is_ok ( ) ) ;
699
+ & candidates[ ..]
703
700
}
704
701
705
702
struct Promoter < ' a , ' tcx > {
@@ -965,7 +962,7 @@ fn promote_candidates<'tcx>(
965
962
body : & mut Body < ' tcx > ,
966
963
tcx : TyCtxt < ' tcx > ,
967
964
mut temps : IndexVec < Local , TempState > ,
968
- candidates : Vec < Candidate > ,
965
+ candidates : & [ Candidate ] ,
969
966
) -> IndexVec < Promoted , Body < ' tcx > > {
970
967
// Visit candidates in reverse, in case they're nested.
971
968
debug ! ( promote_candidates = ?candidates) ;
@@ -978,7 +975,7 @@ fn promote_candidates<'tcx>(
978
975
let mut promotions = IndexVec :: new ( ) ;
979
976
980
977
let mut extra_statements = vec ! [ ] ;
981
- for candidate in candidates. into_iter ( ) . rev ( ) {
978
+ for candidate in candidates. iter ( ) . copied ( ) . rev ( ) {
982
979
let Location { block, statement_index } = candidate. location ;
983
980
if let StatementKind :: Assign ( box ( place, _) ) = & body[ block] . statements [ statement_index] . kind
984
981
{
0 commit comments