@@ -69,8 +69,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
69
69
70
70
let ( temps, all_candidates) = collect_temps_and_candidates ( & ccx, & mut rpo) ;
71
71
72
- let promotable_candidates =
73
- validate_candidates ( tcx, read_only_body, def_id, & temps, & all_candidates) ;
72
+ let promotable_candidates = validate_candidates ( & ccx, & temps, & all_candidates) ;
74
73
75
74
let promoted = promote_candidates ( def_id, body, tcx, temps, promotable_candidates) ;
76
75
self . promoted_fragments . set ( promoted) ;
@@ -267,7 +266,7 @@ pub fn collect_temps_and_candidates(
267
266
///
268
267
/// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion.
269
268
struct Validator < ' a , ' tcx > {
270
- ccx : ConstCx < ' a , ' tcx > ,
269
+ ccx : & ' a ConstCx < ' a , ' tcx > ,
271
270
temps : & ' a IndexVec < Local , TempState > ,
272
271
273
272
/// Explicit promotion happens e.g. for constant arguments declared via
@@ -720,13 +719,11 @@ impl<'tcx> Validator<'_, 'tcx> {
720
719
721
720
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
722
721
pub fn validate_candidates (
723
- tcx : TyCtxt < ' tcx > ,
724
- body : ReadOnlyBodyAndCache < ' _ , ' tcx > ,
725
- def_id : DefId ,
722
+ ccx : & ConstCx < ' _ , ' _ > ,
726
723
temps : & IndexVec < Local , TempState > ,
727
724
candidates : & [ Candidate ] ,
728
725
) -> Vec < Candidate > {
729
- let mut validator = Validator { ccx : ConstCx :: new ( tcx , def_id , body ) , temps, explicit : false } ;
726
+ let mut validator = Validator { ccx, temps, explicit : false } ;
730
727
731
728
candidates
732
729
. iter ( )
@@ -740,9 +737,9 @@ pub fn validate_candidates(
740
737
let is_promotable = validator. validate_candidate ( candidate) . is_ok ( ) ;
741
738
match candidate {
742
739
Candidate :: Argument { bb, index } if !is_promotable => {
743
- let span = body[ bb] . terminator ( ) . source_info . span ;
740
+ let span = ccx . body [ bb] . terminator ( ) . source_info . span ;
744
741
let msg = format ! ( "argument {} is required to be a constant" , index + 1 ) ;
745
- tcx. sess . span_err ( span, & msg) ;
742
+ ccx . tcx . sess . span_err ( span, & msg) ;
746
743
}
747
744
_ => ( ) ,
748
745
}
@@ -1155,7 +1152,7 @@ pub fn promote_candidates<'tcx>(
1155
1152
/// Feature attribute should be suggested if `operand` can be promoted and the feature is not
1156
1153
/// enabled.
1157
1154
crate fn should_suggest_const_in_array_repeat_expressions_attribute < ' tcx > (
1158
- ccx : ConstCx < ' _ , ' tcx > ,
1155
+ ccx : & ConstCx < ' _ , ' tcx > ,
1159
1156
operand : & Operand < ' tcx > ,
1160
1157
) -> bool {
1161
1158
let mut rpo = traversal:: reverse_postorder ( & ccx. body ) ;
0 commit comments