@@ -65,7 +65,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
65
65
let ccx = ConstCx :: new ( tcx, def_id, body) ;
66
66
let ( temps, all_candidates) = collect_temps_and_candidates ( & ccx, & mut rpo) ;
67
67
68
- let promotable_candidates = validate_candidates ( tcx , body , def_id , & temps, & all_candidates) ;
68
+ let promotable_candidates = validate_candidates ( & ccx , & temps, & all_candidates) ;
69
69
70
70
let promoted = promote_candidates ( def_id, body, tcx, temps, promotable_candidates) ;
71
71
self . promoted_fragments . set ( promoted) ;
@@ -262,7 +262,7 @@ pub fn collect_temps_and_candidates(
262
262
///
263
263
/// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion.
264
264
struct Validator < ' a , ' tcx > {
265
- ccx : ConstCx < ' a , ' tcx > ,
265
+ ccx : & ' a ConstCx < ' a , ' tcx > ,
266
266
temps : & ' a IndexVec < Local , TempState > ,
267
267
268
268
/// Explicit promotion happens e.g. for constant arguments declared via
@@ -715,13 +715,11 @@ impl<'tcx> Validator<'_, 'tcx> {
715
715
716
716
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
717
717
pub fn validate_candidates (
718
- tcx : TyCtxt < ' tcx > ,
719
- body : & Body < ' tcx > ,
720
- def_id : DefId ,
718
+ ccx : & ConstCx < ' _ , ' _ > ,
721
719
temps : & IndexVec < Local , TempState > ,
722
720
candidates : & [ Candidate ] ,
723
721
) -> Vec < Candidate > {
724
- let mut validator = Validator { ccx : ConstCx :: new ( tcx , def_id , body ) , temps, explicit : false } ;
722
+ let mut validator = Validator { ccx, temps, explicit : false } ;
725
723
726
724
candidates
727
725
. iter ( )
@@ -735,9 +733,9 @@ pub fn validate_candidates(
735
733
let is_promotable = validator. validate_candidate ( candidate) . is_ok ( ) ;
736
734
match candidate {
737
735
Candidate :: Argument { bb, index } if !is_promotable => {
738
- let span = body[ bb] . terminator ( ) . source_info . span ;
736
+ let span = ccx . body [ bb] . terminator ( ) . source_info . span ;
739
737
let msg = format ! ( "argument {} is required to be a constant" , index + 1 ) ;
740
- tcx. sess . span_err ( span, & msg) ;
738
+ ccx . tcx . sess . span_err ( span, & msg) ;
741
739
}
742
740
_ => ( ) ,
743
741
}
@@ -1145,7 +1143,7 @@ pub fn promote_candidates<'tcx>(
1145
1143
/// Feature attribute should be suggested if `operand` can be promoted and the feature is not
1146
1144
/// enabled.
1147
1145
crate fn should_suggest_const_in_array_repeat_expressions_attribute < ' tcx > (
1148
- ccx : ConstCx < ' _ , ' tcx > ,
1146
+ ccx : & ConstCx < ' _ , ' tcx > ,
1149
1147
operand : & Operand < ' tcx > ,
1150
1148
) -> bool {
1151
1149
let mut rpo = traversal:: reverse_postorder ( & ccx. body ) ;
0 commit comments