1
Fork 0

Use LocalDefId for closures more

This commit is contained in:
Cameron Steffen 2022-07-12 09:10:22 -05:00
parent 1202bbaf48
commit cf2433a74f
29 changed files with 164 additions and 171 deletions

View file

@ -3,7 +3,7 @@
use crate::build::expr::category::Category;
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::LocalDefId;
use rustc_middle::hir::place::Projection as HirProjection;
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
use rustc_middle::middle::region;
@ -58,7 +58,7 @@ pub(crate) enum PlaceBase {
/// HirId of the upvar
var_hir_id: LocalVarId,
/// DefId of the closure
closure_def_id: DefId,
closure_def_id: LocalDefId,
/// The trait closure implements, `Fn`, `FnMut`, `FnOnce`
closure_kind: ty::ClosureKind,
},
@ -176,7 +176,7 @@ fn compute_capture_idx<'tcx>(
fn find_capture_matching_projections<'a, 'tcx>(
typeck_results: &'a ty::TypeckResults<'tcx>,
var_hir_id: LocalVarId,
closure_def_id: DefId,
closure_def_id: LocalDefId,
projections: &[PlaceElem<'tcx>],
) -> Option<(usize, &'a ty::CapturedPlace<'tcx>)> {
let closure_min_captures = typeck_results.closure_min_captures.get(&closure_def_id)?;
@ -242,7 +242,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
};
// We won't be building MIR if the closure wasn't local
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id);
let closure_ty = typeck_results.node_type(closure_hir_id);
let substs = match closure_ty.kind() {
@ -626,11 +626,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn lower_captured_upvar(
&mut self,
block: BasicBlock,
closure_expr_id: LocalDefId,
closure_def_id: LocalDefId,
var_hir_id: LocalVarId,
) -> BlockAnd<PlaceBuilder<'tcx>> {
let closure_ty =
self.typeck_results.node_type(self.tcx.hir().local_def_id_to_hir_id(closure_expr_id));
self.typeck_results.node_type(self.tcx.hir().local_def_id_to_hir_id(closure_def_id));
let closure_kind = if let ty::Closure(_, closure_substs) = closure_ty.kind() {
self.infcx.closure_kind(closure_substs).unwrap()
@ -639,11 +639,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ty::ClosureKind::FnOnce
};
block.and(PlaceBuilder::from(PlaceBase::Upvar {
var_hir_id,
closure_def_id: closure_expr_id.to_def_id(),
closure_kind,
}))
block.and(PlaceBuilder::from(PlaceBase::Upvar { var_hir_id, closure_def_id, closure_kind }))
}
/// Lower an index expression

View file

@ -672,7 +672,7 @@ where
Some(builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
builder.args_and_body(
START_BLOCK,
fn_def.did.to_def_id(),
fn_def.did,
&arguments,
arg_scope,
&thir[expr],
@ -895,7 +895,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn args_and_body(
&mut self,
mut block: BasicBlock,
fn_def_id: DefId,
fn_def_id: LocalDefId,
arguments: &[ArgInfo<'tcx>],
argument_scope: region::Scope,
expr: &Expr<'tcx>,

View file

@ -408,7 +408,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
movability: _,
fake_reads: _,
} => {
let closure_id = closure_id.expect_local();
let closure_def = if let Some((did, const_param_id)) =
ty::WithOptConstParam::try_lookup(closure_id, self.tcx)
{

View file

@ -523,6 +523,7 @@ impl<'tcx> Cx<'tcx> {
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
}
};
let def_id = def_id.expect_local();
let upvars = self
.typeck_results