From 22a53790ede07f2341ff12d62038bd2bc8f4e3e4 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 2 Apr 2020 16:38:50 +0200 Subject: [PATCH] Use `ConstCx` for `validate_candidates` --- src/librustc_mir/borrow_check/type_check/mod.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index e22a4b92ec5..179641ec7c0 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1997,7 +1997,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // be mentioned, need to check if the rvalue is promotable. let should_suggest = should_suggest_const_in_array_repeat_expressions_attribute( - ccx, operand, + &ccx, operand, ); debug!("check_rvalue: should_suggest={:?}", should_suggest); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index ab5a0d99b75..3506abc8e24 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -65,7 +65,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { let ccx = ConstCx::new(tcx, def_id, body); let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo); - let promotable_candidates = validate_candidates(tcx, body, def_id, &temps, &all_candidates); + let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates); let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); @@ -262,7 +262,7 @@ pub fn collect_temps_and_candidates( /// /// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion. struct Validator<'a, 'tcx> { - ccx: ConstCx<'a, 'tcx>, + ccx: &'a ConstCx<'a, 'tcx>, temps: &'a IndexVec, /// Explicit promotion happens e.g. for constant arguments declared via @@ -715,13 +715,11 @@ impl<'tcx> Validator<'_, 'tcx> { // FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`. pub fn validate_candidates( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, - def_id: DefId, + ccx: &ConstCx<'_, '_>, temps: &IndexVec, candidates: &[Candidate], ) -> Vec { - let mut validator = Validator { ccx: ConstCx::new(tcx, def_id, body), temps, explicit: false }; + let mut validator = Validator { ccx, temps, explicit: false }; candidates .iter() @@ -735,9 +733,9 @@ pub fn validate_candidates( let is_promotable = validator.validate_candidate(candidate).is_ok(); match candidate { Candidate::Argument { bb, index } if !is_promotable => { - let span = body[bb].terminator().source_info.span; + let span = ccx.body[bb].terminator().source_info.span; let msg = format!("argument {} is required to be a constant", index + 1); - tcx.sess.span_err(span, &msg); + ccx.tcx.sess.span_err(span, &msg); } _ => (), } @@ -1145,7 +1143,7 @@ pub fn promote_candidates<'tcx>( /// Feature attribute should be suggested if `operand` can be promoted and the feature is not /// enabled. crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>( - ccx: ConstCx<'_, 'tcx>, + ccx: &ConstCx<'_, 'tcx>, operand: &Operand<'tcx>, ) -> bool { let mut rpo = traversal::reverse_postorder(&ccx.body);