Skip to content

Commit 5f044f3

Browse files
committed
BorrowckInferCtxt: infcx by value
1 parent 25e3949 commit 5f044f3

File tree

7 files changed

+31
-40
lines changed

7 files changed

+31
-40
lines changed

compiler/rustc_borrowck/src/consumers.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_index::{IndexSlice, IndexVec};
5-
use rustc_infer::infer::TyCtxtInferExt;
65
use rustc_middle::mir::{Body, Promoted};
76
use rustc_middle::ty::TyCtxt;
87
use std::rc::Rc;
@@ -105,8 +104,7 @@ pub fn get_body_with_borrowck_facts(
105104
options: ConsumerOptions,
106105
) -> BodyWithBorrowckFacts<'_> {
107106
let (input_body, promoted) = tcx.mir_promoted(def);
108-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def).build();
109107
let input_body: &Body<'_> = &input_body.borrow();
110108
let promoted: &IndexSlice<_, _> = &promoted.borrow();
111-
*super::do_mir_borrowck(&infcx, input_body, promoted, Some(options)).1.unwrap()
109+
*super::do_mir_borrowck(tcx, input_body, promoted, Some(options)).1.unwrap()
112110
}

compiler/rustc_borrowck/src/lib.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ use rustc_hir as hir;
2323
use rustc_hir::def_id::LocalDefId;
2424
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
2525
use rustc_index::{IndexSlice, IndexVec};
26-
use rustc_infer::infer::{
27-
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
28-
};
26+
use rustc_infer::infer::TyCtxtInferExt;
27+
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
2928
use rustc_middle::mir::tcx::PlaceTy;
3029
use rustc_middle::mir::*;
3130
use rustc_middle::query::Providers;
@@ -123,9 +122,8 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
123122
return tcx.arena.alloc(result);
124123
}
125124

126-
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def).build();
127125
let promoted: &IndexSlice<_, _> = &promoted.borrow();
128-
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
126+
let opt_closure_req = do_mir_borrowck(tcx, input_body, promoted, None).0;
129127
debug!("mir_borrowck done");
130128

131129
tcx.arena.alloc(opt_closure_req)
@@ -136,18 +134,15 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
136134
/// Use `consumer_options: None` for the default behavior of returning
137135
/// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
138136
/// to the given [`ConsumerOptions`].
139-
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
137+
#[instrument(skip(tcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
140138
fn do_mir_borrowck<'tcx>(
141-
infcx: &InferCtxt<'tcx>,
139+
tcx: TyCtxt<'tcx>,
142140
input_body: &Body<'tcx>,
143141
input_promoted: &IndexSlice<Promoted, Body<'tcx>>,
144142
consumer_options: Option<ConsumerOptions>,
145143
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
146144
let def = input_body.source.def_id().expect_local();
147-
debug!(?def);
148-
149-
let tcx = infcx.tcx;
150-
let infcx = BorrowckInferCtxt::new(infcx);
145+
let infcx = BorrowckInferCtxt::new(tcx, def);
151146
let param_env = tcx.param_env(def);
152147

153148
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
@@ -440,13 +435,14 @@ fn do_mir_borrowck<'tcx>(
440435
(result, body_with_facts)
441436
}
442437

443-
pub struct BorrowckInferCtxt<'cx, 'tcx> {
444-
pub(crate) infcx: &'cx InferCtxt<'tcx>,
438+
pub struct BorrowckInferCtxt<'tcx> {
439+
pub(crate) infcx: InferCtxt<'tcx>,
445440
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
446441
}
447442

448-
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
449-
pub(crate) fn new(infcx: &'cx InferCtxt<'tcx>) -> Self {
443+
impl<'tcx> BorrowckInferCtxt<'tcx> {
444+
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
445+
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def_id).build();
450446
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
451447
}
452448

@@ -494,16 +490,16 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
494490
}
495491
}
496492

497-
impl<'cx, 'tcx> Deref for BorrowckInferCtxt<'cx, 'tcx> {
493+
impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
498494
type Target = InferCtxt<'tcx>;
499495

500-
fn deref(&self) -> &'cx Self::Target {
501-
self.infcx
496+
fn deref(&self) -> &Self::Target {
497+
&self.infcx
502498
}
503499
}
504500

505501
struct MirBorrowckCtxt<'cx, 'tcx> {
506-
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
502+
infcx: &'cx BorrowckInferCtxt<'tcx>,
507503
param_env: ParamEnv<'tcx>,
508504
body: &'cx Body<'tcx>,
509505
move_data: &'cx MoveData<'tcx>,

compiler/rustc_borrowck/src/nll.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) struct NllOutput<'tcx> {
5151
/// `compute_regions`.
5252
#[instrument(skip(infcx, param_env, body, promoted), level = "debug")]
5353
pub(crate) fn replace_regions_in_mir<'tcx>(
54-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
54+
infcx: &BorrowckInferCtxt<'tcx>,
5555
param_env: ty::ParamEnv<'tcx>,
5656
body: &mut Body<'tcx>,
5757
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
@@ -75,7 +75,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
7575
///
7676
/// This may result in errors being reported.
7777
pub(crate) fn compute_regions<'cx, 'tcx>(
78-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
78+
infcx: &BorrowckInferCtxt<'tcx>,
7979
universal_regions: UniversalRegions<'tcx>,
8080
body: &Body<'tcx>,
8181
promoted: &IndexSlice<Promoted, Body<'tcx>>,
@@ -202,7 +202,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
202202
}
203203

204204
pub(super) fn dump_mir_results<'tcx>(
205-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
205+
infcx: &BorrowckInferCtxt<'tcx>,
206206
body: &Body<'tcx>,
207207
regioncx: &RegionInferenceContext<'tcx>,
208208
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
@@ -254,7 +254,7 @@ pub(super) fn dump_mir_results<'tcx>(
254254
#[allow(rustc::diagnostic_outside_of_impl)]
255255
#[allow(rustc::untranslatable_diagnostic)]
256256
pub(super) fn dump_annotation<'tcx>(
257-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
257+
infcx: &BorrowckInferCtxt<'tcx>,
258258
body: &Body<'tcx>,
259259
regioncx: &RegionInferenceContext<'tcx>,
260260
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ pub enum ExtraConstraintInfo {
250250
}
251251

252252
#[instrument(skip(infcx, sccs), level = "debug")]
253-
fn sccs_info<'cx, 'tcx>(
254-
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
255-
sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
256-
) {
253+
fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>) {
257254
use crate::renumber::RegionCtxt;
258255

259256
let var_to_origin = infcx.reg_var_to_origin.borrow();
@@ -322,8 +319,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
322319
///
323320
/// The `outlives_constraints` and `type_tests` are an initial set
324321
/// of constraints produced by the MIR type check.
325-
pub(crate) fn new<'cx>(
326-
_infcx: &BorrowckInferCtxt<'cx, 'tcx>,
322+
pub(crate) fn new(
323+
_infcx: &BorrowckInferCtxt<'tcx>,
327324
var_infos: VarInfos,
328325
universal_regions: Rc<UniversalRegions<'tcx>>,
329326
placeholder_indices: Rc<PlaceholderIndices>,

compiler/rustc_borrowck/src/renumber.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_span::Symbol;
1111
/// inference variables, returning the number of variables created.
1212
#[instrument(skip(infcx, body, promoted), level = "debug")]
1313
pub fn renumber_mir<'tcx>(
14-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
14+
infcx: &BorrowckInferCtxt<'tcx>,
1515
body: &mut Body<'tcx>,
1616
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
1717
) {
@@ -57,7 +57,7 @@ impl RegionCtxt {
5757
}
5858

5959
struct RegionRenumberer<'a, 'tcx> {
60-
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
60+
infcx: &'a BorrowckInferCtxt<'tcx>,
6161
}
6262

6363
impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> {

compiler/rustc_borrowck/src/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod relate_tys;
122122
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
123123
/// - `elements` -- MIR region map
124124
pub(crate) fn type_check<'mir, 'tcx>(
125-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
125+
infcx: &BorrowckInferCtxt<'tcx>,
126126
param_env: ty::ParamEnv<'tcx>,
127127
body: &Body<'tcx>,
128128
promoted: &IndexSlice<Promoted, Body<'tcx>>,
@@ -865,7 +865,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
865865
/// way, it accrues region constraints -- these can later be used by
866866
/// NLL region checking.
867867
struct TypeChecker<'a, 'tcx> {
868-
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
868+
infcx: &'a BorrowckInferCtxt<'tcx>,
869869
param_env: ty::ParamEnv<'tcx>,
870870
last_span: Span,
871871
body: &'a Body<'tcx>,
@@ -1020,7 +1020,7 @@ impl Locations {
10201020

10211021
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10221022
fn new(
1023-
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
1023+
infcx: &'a BorrowckInferCtxt<'tcx>,
10241024
body: &'a Body<'tcx>,
10251025
param_env: ty::ParamEnv<'tcx>,
10261026
region_bound_pairs: &'a RegionBoundPairs<'tcx>,

compiler/rustc_borrowck/src/universal_regions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'tcx> UniversalRegions<'tcx> {
240240
/// signature. This will also compute the relationships that are
241241
/// known between those regions.
242242
pub fn new(
243-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
243+
infcx: &BorrowckInferCtxt<'tcx>,
244244
mir_def: LocalDefId,
245245
param_env: ty::ParamEnv<'tcx>,
246246
) -> Self {
@@ -411,7 +411,7 @@ impl<'tcx> UniversalRegions<'tcx> {
411411
}
412412

413413
struct UniversalRegionsBuilder<'cx, 'tcx> {
414-
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
414+
infcx: &'cx BorrowckInferCtxt<'tcx>,
415415
mir_def: LocalDefId,
416416
param_env: ty::ParamEnv<'tcx>,
417417
}
@@ -796,7 +796,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
796796
}
797797

798798
#[extension(trait InferCtxtExt<'tcx>)]
799-
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
799+
impl<'tcx> BorrowckInferCtxt<'tcx> {
800800
#[instrument(skip(self), level = "debug")]
801801
fn replace_free_regions_with_nll_infer_vars<T>(
802802
&self,

0 commit comments

Comments
 (0)