Skip to content

Commit 2e35cf9

Browse files
Replace (Body, WithOptConstParam) with Body where possible
1 parent 52484c5 commit 2e35cf9

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/rustc_mir/src/borrow_check/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn mir_borrowck<'tcx>(
111111
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
112112
let input_body: &Body<'_> = &input_body.borrow();
113113
let promoted: &IndexVec<_, _> = &promoted.borrow();
114-
do_mir_borrowck(&infcx, input_body, promoted, def)
114+
do_mir_borrowck(&infcx, input_body, promoted)
115115
});
116116
debug!("mir_borrowck done");
117117

@@ -122,8 +122,9 @@ fn do_mir_borrowck<'a, 'tcx>(
122122
infcx: &InferCtxt<'a, 'tcx>,
123123
input_body: &Body<'tcx>,
124124
input_promoted: &IndexVec<Promoted, Body<'tcx>>,
125-
def: ty::WithOptConstParam<LocalDefId>,
126125
) -> BorrowCheckResult<'tcx> {
126+
let def = input_body.source.with_opt_param().as_local().unwrap();
127+
127128
debug!("do_mir_borrowck(def = {:?})", def);
128129

129130
let tcx = infcx.tcx;
@@ -185,7 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
185186
// will have a lifetime tied to the inference context.
186187
let mut body = input_body.clone();
187188
let mut promoted = input_promoted.clone();
188-
let free_regions = nll::replace_regions_in_mir(infcx, def, param_env, &mut body, &mut promoted);
189+
let free_regions = nll::replace_regions_in_mir(infcx, param_env, &mut body, &mut promoted);
189190
let body = &body; // no further changes
190191

191192
let location_table = &LocationTable::new(&body);

compiler/rustc_mir/src/borrow_check/nll.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_errors::Diagnostic;
5-
use rustc_hir::def_id::{DefId, LocalDefId};
5+
use rustc_hir::def_id::DefId;
66
use rustc_index::vec::IndexVec;
77
use rustc_infer::infer::InferCtxt;
88
use rustc_middle::mir::{
@@ -58,11 +58,12 @@ crate struct NllOutput<'tcx> {
5858
/// `compute_regions`.
5959
pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>(
6060
infcx: &InferCtxt<'cx, 'tcx>,
61-
def: ty::WithOptConstParam<LocalDefId>,
6261
param_env: ty::ParamEnv<'tcx>,
6362
body: &mut Body<'tcx>,
6463
promoted: &mut IndexVec<Promoted, Body<'tcx>>,
6564
) -> UniversalRegions<'tcx> {
65+
let def = body.source.with_opt_param().as_local().unwrap();
66+
6667
debug!("replace_regions_in_mir(def={:?})", def);
6768

6869
// Compute named region information. This also renumbers the inputs/outputs.

compiler/rustc_mir/src/transform/promote_consts.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6060
return;
6161
}
6262

63-
let def = body.source.with_opt_param().expect_local();
64-
6563
let mut rpo = traversal::reverse_postorder(body);
6664
let ccx = ConstCx::new(tcx, body);
6765
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
6866

6967
let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates);
7068

71-
let promoted = promote_candidates(def.to_global(), body, tcx, temps, promotable_candidates);
69+
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
7270
self.promoted_fragments.set(promoted);
7371
}
7472
}
@@ -970,10 +968,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
970968

971969
fn promote_candidate(
972970
mut self,
973-
def: ty::WithOptConstParam<DefId>,
974971
candidate: Candidate,
975972
next_promoted_id: usize,
976973
) -> Option<Body<'tcx>> {
974+
let def = self.source.source.with_opt_param();
977975
let mut rvalue = {
978976
let promoted = &mut self.promoted;
979977
let promoted_id = Promoted::new(next_promoted_id);
@@ -1133,7 +1131,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
11331131
}
11341132

11351133
pub fn promote_candidates<'tcx>(
1136-
def: ty::WithOptConstParam<DefId>,
11371134
body: &mut Body<'tcx>,
11381135
tcx: TyCtxt<'tcx>,
11391136
mut temps: IndexVec<Local, TempState>,
@@ -1191,7 +1188,7 @@ pub fn promote_candidates<'tcx>(
11911188
};
11921189

11931190
//FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice
1194-
if let Some(mut promoted) = promoter.promote_candidate(def, candidate, promotions.len()) {
1191+
if let Some(mut promoted) = promoter.promote_candidate(candidate, promotions.len()) {
11951192
promoted.source.promoted = Some(promotions.next_index());
11961193
promotions.push(promoted);
11971194
}

0 commit comments

Comments
 (0)