BorrowckInferCtxt: infcx by value
This commit is contained in:
parent
25e3949aa1
commit
5f044f3528
7 changed files with 31 additions and 40 deletions
|
@ -23,9 +23,8 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_infer::infer::{
|
||||
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
|
||||
};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
|
||||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::query::Providers;
|
||||
|
@ -123,9 +122,8 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
|
|||
return tcx.arena.alloc(result);
|
||||
}
|
||||
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def).build();
|
||||
let promoted: &IndexSlice<_, _> = &promoted.borrow();
|
||||
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
|
||||
let opt_closure_req = do_mir_borrowck(tcx, input_body, promoted, None).0;
|
||||
debug!("mir_borrowck done");
|
||||
|
||||
tcx.arena.alloc(opt_closure_req)
|
||||
|
@ -136,18 +134,15 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
|
|||
/// Use `consumer_options: None` for the default behavior of returning
|
||||
/// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
|
||||
/// to the given [`ConsumerOptions`].
|
||||
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
|
||||
#[instrument(skip(tcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
|
||||
fn do_mir_borrowck<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
input_body: &Body<'tcx>,
|
||||
input_promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||
consumer_options: Option<ConsumerOptions>,
|
||||
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
||||
let def = input_body.source.def_id().expect_local();
|
||||
debug!(?def);
|
||||
|
||||
let tcx = infcx.tcx;
|
||||
let infcx = BorrowckInferCtxt::new(infcx);
|
||||
let infcx = BorrowckInferCtxt::new(tcx, def);
|
||||
let param_env = tcx.param_env(def);
|
||||
|
||||
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
||||
|
@ -440,13 +435,14 @@ fn do_mir_borrowck<'tcx>(
|
|||
(result, body_with_facts)
|
||||
}
|
||||
|
||||
pub struct BorrowckInferCtxt<'cx, 'tcx> {
|
||||
pub(crate) infcx: &'cx InferCtxt<'tcx>,
|
||||
pub struct BorrowckInferCtxt<'tcx> {
|
||||
pub(crate) infcx: InferCtxt<'tcx>,
|
||||
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
|
||||
pub(crate) fn new(infcx: &'cx InferCtxt<'tcx>) -> Self {
|
||||
impl<'tcx> BorrowckInferCtxt<'tcx> {
|
||||
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
|
||||
let infcx = tcx.infer_ctxt().with_opaque_type_inference(def_id).build();
|
||||
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
|
||||
}
|
||||
|
||||
|
@ -494,16 +490,16 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Deref for BorrowckInferCtxt<'cx, 'tcx> {
|
||||
impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
|
||||
type Target = InferCtxt<'tcx>;
|
||||
|
||||
fn deref(&self) -> &'cx Self::Target {
|
||||
self.infcx
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.infcx
|
||||
}
|
||||
}
|
||||
|
||||
struct MirBorrowckCtxt<'cx, 'tcx> {
|
||||
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
|
||||
infcx: &'cx BorrowckInferCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
body: &'cx Body<'tcx>,
|
||||
move_data: &'cx MoveData<'tcx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue