Skip to content

Commit 04a94ab

Browse files
Remove DefId from MirBorrowckCtxt
1 parent fff3b75 commit 04a94ab

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
336336
};
337337
if let ty::Param(param_ty) = ty.kind() {
338338
let tcx = self.infcx.tcx;
339-
let generics = tcx.generics_of(self.mir_def_id);
339+
let generics = tcx.generics_of(self.mir_def_id());
340340
let param = generics.type_param(&param_ty, tcx);
341-
if let Some(generics) =
342-
tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id.to_def_id()))
341+
if let Some(generics) = tcx
342+
.hir()
343+
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id()))
343344
{
344345
suggest_constraining_type_param(
345346
tcx,
@@ -1004,7 +1005,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10041005
format!("`{}` would have to be valid for `{}`...", name, region_name),
10051006
);
10061007

1007-
let fn_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
1008+
let fn_hir_id = self.mir_hir_id();
10081009
err.span_label(
10091010
drop_span,
10101011
format!(
@@ -1019,7 +1020,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10191020
match &self
10201021
.infcx
10211022
.tcx
1022-
.typeck(self.mir_def_id)
1023+
.typeck(self.mir_def_id())
10231024
.node_type(fn_hir_id)
10241025
.kind()
10251026
{
@@ -1369,7 +1370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13691370
) -> DiagnosticBuilder<'cx> {
13701371
let tcx = self.infcx.tcx;
13711372

1372-
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id.to_def_id());
1373+
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
13731374

13741375
let mut err =
13751376
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
@@ -1708,15 +1709,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17081709
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
17091710
// Define a fallback for when we can't match a closure.
17101711
let fallback = || {
1711-
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id.to_def_id());
1712+
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id().to_def_id());
17121713
if is_closure {
17131714
None
17141715
} else {
1715-
let ty = self.infcx.tcx.type_of(self.mir_def_id);
1716+
let ty = self.infcx.tcx.type_of(self.mir_def_id());
17161717
match ty.kind() {
17171718
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
1718-
self.mir_def_id.to_def_id(),
1719-
self.infcx.tcx.fn_sig(self.mir_def_id),
1719+
self.mir_def_id().to_def_id(),
1720+
self.infcx.tcx.fn_sig(self.mir_def_id()),
17201721
),
17211722
_ => None,
17221723
}

compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
331331
self.cannot_move_out_of_interior_noncopy(span, ty, None)
332332
}
333333
ty::Closure(def_id, closure_substs)
334-
if def_id.as_local() == Some(self.mir_def_id) && upvar_field.is_some() =>
334+
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
335335
{
336336
let closure_kind_ty = closure_substs.as_closure().kind_ty();
337337
let closure_kind = closure_kind_ty.to_opt_closure_kind();

compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
492492
err.span_label(sp, format!("cannot {}", act));
493493

494494
let hir = self.infcx.tcx.hir();
495-
let closure_id = hir.local_def_id_to_hir_id(self.mir_def_id);
495+
let closure_id = self.mir_hir_id();
496496
let fn_call_id = hir.get_parent_node(closure_id);
497497
let node = hir.get(fn_call_id);
498498
let item_id = hir.enclosing_body_owner(fn_call_id);

compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
515515
let mut diag =
516516
self.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
517517

518-
let (_, mir_def_name) = self.infcx.tcx.article_and_description(self.mir_def_id.to_def_id());
518+
let (_, mir_def_name) =
519+
self.infcx.tcx.article_and_description(self.mir_def_id().to_def_id());
519520

520521
let fr_name = self.give_region_a_name(*fr).unwrap();
521522
fr_name.highlight_region_name(&mut diag);

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ impl Display for RegionName {
147147
}
148148

149149
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
150+
crate fn mir_def_id(&self) -> hir::def_id::LocalDefId {
151+
self.body.source.def_id().as_local().unwrap()
152+
}
153+
154+
crate fn mir_hir_id(&self) -> hir::HirId {
155+
self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id())
156+
}
157+
150158
/// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
151159
/// increment the counter.
152160
///
@@ -266,12 +274,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
266274
}
267275

268276
ty::BoundRegion::BrEnv => {
269-
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
270277
let def_ty = self.regioncx.universal_regions().defining_ty;
271278

272279
if let DefiningTy::Closure(_, substs) = def_ty {
273280
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
274-
tcx.hir().expect_expr(mir_hir_id).kind
281+
tcx.hir().expect_expr(self.mir_hir_id()).kind
275282
{
276283
span
277284
} else {
@@ -361,8 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
361368
&self,
362369
argument_index: usize,
363370
) -> Option<&hir::Ty<'tcx>> {
364-
let mir_hir_id = self.infcx.tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
365-
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
371+
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(self.mir_hir_id())?;
366372
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
367373
match argument_hir_ty.kind {
368374
// This indicates a variable with no type annotation, like
@@ -649,9 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
649655
let type_name =
650656
self.infcx.extract_inference_diagnostics_data(return_ty.into(), Some(highlight)).name;
651657

652-
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
653-
654-
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
658+
let (return_span, mir_description) = match tcx.hir().get(self.mir_hir_id()) {
655659
hir::Node::Expr(hir::Expr {
656660
kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
657661
..
@@ -702,9 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
702706
let type_name =
703707
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;
704708

705-
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(self.mir_def_id);
706-
707-
let yield_span = match tcx.hir().get(mir_hir_id) {
709+
let yield_span = match tcx.hir().get(self.mir_hir_id()) {
708710
hir::Node::Expr(hir::Expr {
709711
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
710712
}) => (tcx.sess.source_map().end_point(*span)),

compiler/rustc_mir/src/borrow_check/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ fn do_mir_borrowck<'a, 'tcx>(
285285
infcx,
286286
param_env,
287287
body: promoted_body,
288-
mir_def_id: def.did,
289288
move_data: &move_data,
290289
location_table: &LocationTable::new(promoted_body),
291290
movable_generator,
@@ -319,7 +318,6 @@ fn do_mir_borrowck<'a, 'tcx>(
319318
infcx,
320319
param_env,
321320
body,
322-
mir_def_id: def.did,
323321
move_data: &mdpe.move_data,
324322
location_table,
325323
movable_generator,
@@ -473,7 +471,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
473471
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
474472
param_env: ParamEnv<'tcx>,
475473
body: &'cx Body<'tcx>,
476-
mir_def_id: LocalDefId,
477474
move_data: &'cx MoveData<'tcx>,
478475

479476
/// Map from MIR `Location` to `LocationIndex`; created

0 commit comments

Comments
 (0)