From 2e35cf973bea64f2d5afbe1f321e2b7a15967ab6 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 4 Oct 2020 16:59:19 -0700 Subject: [PATCH] Replace `(Body, WithOptConstParam)` with `Body` where possible --- compiler/rustc_mir/src/borrow_check/mod.rs | 7 ++++--- compiler/rustc_mir/src/borrow_check/nll.rs | 5 +++-- compiler/rustc_mir/src/transform/promote_consts.rs | 9 +++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/mod.rs b/compiler/rustc_mir/src/borrow_check/mod.rs index ad874be6ee9..3c72852e017 100644 --- a/compiler/rustc_mir/src/borrow_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/mod.rs @@ -111,7 +111,7 @@ fn mir_borrowck<'tcx>( let opt_closure_req = tcx.infer_ctxt().enter(|infcx| { let input_body: &Body<'_> = &input_body.borrow(); let promoted: &IndexVec<_, _> = &promoted.borrow(); - do_mir_borrowck(&infcx, input_body, promoted, def) + do_mir_borrowck(&infcx, input_body, promoted) }); debug!("mir_borrowck done"); @@ -122,8 +122,9 @@ fn do_mir_borrowck<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, input_body: &Body<'tcx>, input_promoted: &IndexVec>, - def: ty::WithOptConstParam, ) -> BorrowCheckResult<'tcx> { + let def = input_body.source.with_opt_param().as_local().unwrap(); + debug!("do_mir_borrowck(def = {:?})", def); let tcx = infcx.tcx; @@ -185,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>( // will have a lifetime tied to the inference context. let mut body = input_body.clone(); let mut promoted = input_promoted.clone(); - let free_regions = nll::replace_regions_in_mir(infcx, def, param_env, &mut body, &mut promoted); + let free_regions = nll::replace_regions_in_mir(infcx, param_env, &mut body, &mut promoted); let body = &body; // no further changes let location_table = &LocationTable::new(&body); diff --git a/compiler/rustc_mir/src/borrow_check/nll.rs b/compiler/rustc_mir/src/borrow_check/nll.rs index 70f068997b6..a1f8df1922f 100644 --- a/compiler/rustc_mir/src/borrow_check/nll.rs +++ b/compiler/rustc_mir/src/borrow_check/nll.rs @@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::Diagnostic; -use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::{ @@ -58,11 +58,12 @@ /// `compute_regions`. pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, - def: ty::WithOptConstParam, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, promoted: &mut IndexVec>, ) -> UniversalRegions<'tcx> { + let def = body.source.with_opt_param().as_local().unwrap(); + debug!("replace_regions_in_mir(def={:?})", def); // Compute named region information. This also renumbers the inputs/outputs. diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs index 5fd47128631..7abc998d388 100644 --- a/compiler/rustc_mir/src/transform/promote_consts.rs +++ b/compiler/rustc_mir/src/transform/promote_consts.rs @@ -60,15 +60,13 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { return; } - let def = body.source.with_opt_param().expect_local(); - let mut rpo = traversal::reverse_postorder(body); let ccx = ConstCx::new(tcx, body); let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo); let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates); - let promoted = promote_candidates(def.to_global(), body, tcx, temps, promotable_candidates); + let promoted = promote_candidates(body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); } } @@ -970,10 +968,10 @@ fn promote_temp(&mut self, temp: Local) -> Local { fn promote_candidate( mut self, - def: ty::WithOptConstParam, candidate: Candidate, next_promoted_id: usize, ) -> Option> { + let def = self.source.source.with_opt_param(); let mut rvalue = { let promoted = &mut self.promoted; let promoted_id = Promoted::new(next_promoted_id); @@ -1133,7 +1131,6 @@ fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) { } pub fn promote_candidates<'tcx>( - def: ty::WithOptConstParam, body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, @@ -1191,7 +1188,7 @@ pub fn promote_candidates<'tcx>( }; //FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice - if let Some(mut promoted) = promoter.promote_candidate(def, candidate, promotions.len()) { + if let Some(mut promoted) = promoter.promote_candidate(candidate, promotions.len()) { promoted.source.promoted = Some(promotions.next_index()); promotions.push(promoted); }