Remove DefId from MirBorrowckCtxt

This commit is contained in:
Dylan MacKenzie 2020-10-04 17:23:02 -07:00
parent fff3b7596a
commit 04a94abcb9
6 changed files with 27 additions and 26 deletions

View file

@ -336,10 +336,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
};
if let ty::Param(param_ty) = ty.kind() {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id);
let generics = tcx.generics_of(self.mir_def_id());
let param = generics.type_param(&param_ty, tcx);
if let Some(generics) =
tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id.to_def_id()))
if let Some(generics) = tcx
.hir()
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id()))
{
suggest_constraining_type_param(
tcx,
@ -1004,7 +1005,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("`{}` would have to be valid for `{}`...", name, region_name),
);
let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let fn_hir_id = self.mir_hir_id();
err.span_label(
drop_span,
format!(
@ -1019,7 +1020,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match &self
.infcx
.tcx
.typeck(self.mir_def_id)
.typeck(self.mir_def_id())
.node_type(fn_hir_id)
.kind()
{
@ -1369,7 +1370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> DiagnosticBuilder<'cx> {
let tcx = self.infcx.tcx;
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id.to_def_id());
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
let mut err =
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
@ -1708,15 +1709,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
// Define a fallback for when we can't match a closure.
let fallback = || {
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id.to_def_id());
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id().to_def_id());
if is_closure {
None
} else {
let ty = self.infcx.tcx.type_of(self.mir_def_id);
let ty = self.infcx.tcx.type_of(self.mir_def_id());
match ty.kind() {
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
self.mir_def_id.to_def_id(),
self.infcx.tcx.fn_sig(self.mir_def_id),
self.mir_def_id().to_def_id(),
self.infcx.tcx.fn_sig(self.mir_def_id()),
),
_ => None,
}

View file

@ -331,7 +331,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
self.cannot_move_out_of_interior_noncopy(span, ty, None)
}
ty::Closure(def_id, closure_substs)
if def_id.as_local() == Some(self.mir_def_id) && upvar_field.is_some() =>
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
{
let closure_kind_ty = closure_substs.as_closure().kind_ty();
let closure_kind = closure_kind_ty.to_opt_closure_kind();

View file

@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(sp, format!("cannot {}", act));
let hir = self.infcx.tcx.hir();
let closure_id = hir.local_def_id_to_hir_id(self.mir_def_id);
let closure_id = self.mir_hir_id();
let fn_call_id = hir.get_parent_node(closure_id);
let node = hir.get(fn_call_id);
let item_id = hir.enclosing_body_owner(fn_call_id);

View file

@ -515,7 +515,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let mut diag =
self.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
let (_, mir_def_name) = self.infcx.tcx.article_and_description(self.mir_def_id.to_def_id());
let (_, mir_def_name) =
self.infcx.tcx.article_and_description(self.mir_def_id().to_def_id());
let fr_name = self.give_region_a_name(*fr).unwrap();
fr_name.highlight_region_name(&mut diag);

View file

@ -147,6 +147,14 @@ impl Display for RegionName {
}
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
crate fn mir_def_id(&self) -> hir::def_id::LocalDefId {
self.body.source.def_id().as_local().unwrap()
}
crate fn mir_hir_id(&self) -> hir::HirId {
self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id())
}
/// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
/// increment the counter.
///
@ -266,12 +274,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}
ty::BoundRegion::BrEnv => {
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let def_ty = self.regioncx.universal_regions().defining_ty;
if let DefiningTy::Closure(_, substs) = def_ty {
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
tcx.hir().expect_expr(mir_hir_id).kind
tcx.hir().expect_expr(self.mir_hir_id()).kind
{
span
} else {
@ -361,8 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
&self,
argument_index: usize,
) -> Option<&hir::Ty<'tcx>> {
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(self.mir_hir_id())?;
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
match argument_hir_ty.kind {
// This indicates a variable with no type annotation, like
@ -649,9 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
let type_name =
self.infcx.extract_inference_diagnostics_data(return_ty.into(), Some(highlight)).name;
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
let (return_span, mir_description) = match tcx.hir().get(self.mir_hir_id()) {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
..
@ -702,9 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
let type_name =
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
let yield_span = match tcx.hir().get(mir_hir_id) {
let yield_span = match tcx.hir().get(self.mir_hir_id()) {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
}) => (tcx.sess.source_map().end_point(*span)),

View file

@ -285,7 +285,6 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx,
param_env,
body: promoted_body,
mir_def_id: def.did,
move_data: &move_data,
location_table: &LocationTable::new(promoted_body),
movable_generator,
@ -319,7 +318,6 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx,
param_env,
body,
mir_def_id: def.did,
move_data: &mdpe.move_data,
location_table,
movable_generator,
@ -473,7 +471,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
param_env: ParamEnv<'tcx>,
body: &'cx Body<'tcx>,
mir_def_id: LocalDefId,
move_data: &'cx MoveData<'tcx>,
/// Map from MIR `Location` to `LocationIndex`; created