Skip to content

Commit 22a5379

Browse files
committed
Use ConstCx for validate_candidates
1 parent 0bc743e commit 22a5379

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19971997
// be mentioned, need to check if the rvalue is promotable.
19981998
let should_suggest =
19991999
should_suggest_const_in_array_repeat_expressions_attribute(
2000-
ccx, operand,
2000+
&ccx, operand,
20012001
);
20022002
debug!("check_rvalue: should_suggest={:?}", should_suggest);
20032003

src/librustc_mir/transform/promote_consts.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6565
let ccx = ConstCx::new(tcx, def_id, body);
6666
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
6767

68-
let promotable_candidates = validate_candidates(tcx, body, def_id, &temps, &all_candidates);
68+
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
6969

7070
let promoted = promote_candidates(def_id, body, tcx, temps, promotable_candidates);
7171
self.promoted_fragments.set(promoted);
@@ -262,7 +262,7 @@ pub fn collect_temps_and_candidates(
262262
///
263263
/// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion.
264264
struct Validator<'a, 'tcx> {
265-
ccx: ConstCx<'a, 'tcx>,
265+
ccx: &'a ConstCx<'a, 'tcx>,
266266
temps: &'a IndexVec<Local, TempState>,
267267

268268
/// Explicit promotion happens e.g. for constant arguments declared via
@@ -715,13 +715,11 @@ impl<'tcx> Validator<'_, 'tcx> {
715715

716716
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
717717
pub fn validate_candidates(
718-
tcx: TyCtxt<'tcx>,
719-
body: &Body<'tcx>,
720-
def_id: DefId,
718+
ccx: &ConstCx<'_, '_>,
721719
temps: &IndexVec<Local, TempState>,
722720
candidates: &[Candidate],
723721
) -> 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 };
725723

726724
candidates
727725
.iter()
@@ -735,9 +733,9 @@ pub fn validate_candidates(
735733
let is_promotable = validator.validate_candidate(candidate).is_ok();
736734
match candidate {
737735
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;
739737
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);
741739
}
742740
_ => (),
743741
}
@@ -1145,7 +1143,7 @@ pub fn promote_candidates<'tcx>(
11451143
/// Feature attribute should be suggested if `operand` can be promoted and the feature is not
11461144
/// enabled.
11471145
crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>(
1148-
ccx: ConstCx<'_, 'tcx>,
1146+
ccx: &ConstCx<'_, 'tcx>,
11491147
operand: &Operand<'tcx>,
11501148
) -> bool {
11511149
let mut rpo = traversal::reverse_postorder(&ccx.body);

0 commit comments

Comments
 (0)