Remove DefId
from MirBorrowckCtxt
This commit is contained in:
parent
fff3b7596a
commit
04a94abcb9
@ -336,10 +336,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
};
|
};
|
||||||
if let ty::Param(param_ty) = ty.kind() {
|
if let ty::Param(param_ty) = ty.kind() {
|
||||||
let tcx = self.infcx.tcx;
|
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(¶m_ty, tcx);
|
let param = generics.type_param(¶m_ty, tcx);
|
||||||
if let Some(generics) =
|
if let Some(generics) = tcx
|
||||||
tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id.to_def_id()))
|
.hir()
|
||||||
|
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id()))
|
||||||
{
|
{
|
||||||
suggest_constraining_type_param(
|
suggest_constraining_type_param(
|
||||||
tcx,
|
tcx,
|
||||||
@ -1004,7 +1005,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
format!("`{}` would have to be valid for `{}`...", name, region_name),
|
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(
|
err.span_label(
|
||||||
drop_span,
|
drop_span,
|
||||||
format!(
|
format!(
|
||||||
@ -1019,7 +1020,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
match &self
|
match &self
|
||||||
.infcx
|
.infcx
|
||||||
.tcx
|
.tcx
|
||||||
.typeck(self.mir_def_id)
|
.typeck(self.mir_def_id())
|
||||||
.node_type(fn_hir_id)
|
.node_type(fn_hir_id)
|
||||||
.kind()
|
.kind()
|
||||||
{
|
{
|
||||||
@ -1369,7 +1370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
) -> DiagnosticBuilder<'cx> {
|
) -> DiagnosticBuilder<'cx> {
|
||||||
let tcx = self.infcx.tcx;
|
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 =
|
let mut err =
|
||||||
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
|
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
|
||||||
@ -1708,15 +1709,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
||||||
// Define a fallback for when we can't match a closure.
|
// Define a fallback for when we can't match a closure.
|
||||||
let fallback = || {
|
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 {
|
if is_closure {
|
||||||
None
|
None
|
||||||
} else {
|
} 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() {
|
match ty.kind() {
|
||||||
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
|
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
|
||||||
self.mir_def_id.to_def_id(),
|
self.mir_def_id().to_def_id(),
|
||||||
self.infcx.tcx.fn_sig(self.mir_def_id),
|
self.infcx.tcx.fn_sig(self.mir_def_id()),
|
||||||
),
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
self.cannot_move_out_of_interior_noncopy(span, ty, None)
|
self.cannot_move_out_of_interior_noncopy(span, ty, None)
|
||||||
}
|
}
|
||||||
ty::Closure(def_id, closure_substs)
|
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_ty = closure_substs.as_closure().kind_ty();
|
||||||
let closure_kind = closure_kind_ty.to_opt_closure_kind();
|
let closure_kind = closure_kind_ty.to_opt_closure_kind();
|
||||||
|
@ -492,7 +492,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
err.span_label(sp, format!("cannot {}", act));
|
err.span_label(sp, format!("cannot {}", act));
|
||||||
|
|
||||||
let hir = self.infcx.tcx.hir();
|
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 fn_call_id = hir.get_parent_node(closure_id);
|
||||||
let node = hir.get(fn_call_id);
|
let node = hir.get(fn_call_id);
|
||||||
let item_id = hir.enclosing_body_owner(fn_call_id);
|
let item_id = hir.enclosing_body_owner(fn_call_id);
|
||||||
|
@ -515,7 +515,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||||||
let mut diag =
|
let mut diag =
|
||||||
self.infcx.tcx.sess.struct_span_err(*span, "lifetime may not live long enough");
|
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();
|
let fr_name = self.give_region_a_name(*fr).unwrap();
|
||||||
fr_name.highlight_region_name(&mut diag);
|
fr_name.highlight_region_name(&mut diag);
|
||||||
|
@ -147,6 +147,14 @@ impl Display for RegionName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
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,
|
/// Generate a synthetic region named `'N`, where `N` is the next value of the counter. Then,
|
||||||
/// increment the counter.
|
/// increment the counter.
|
||||||
///
|
///
|
||||||
@ -266,12 +274,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ty::BoundRegion::BrEnv => {
|
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;
|
let def_ty = self.regioncx.universal_regions().defining_ty;
|
||||||
|
|
||||||
if let DefiningTy::Closure(_, substs) = def_ty {
|
if let DefiningTy::Closure(_, substs) = def_ty {
|
||||||
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
|
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
|
span
|
||||||
} else {
|
} else {
|
||||||
@ -361,8 +368,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
argument_index: usize,
|
argument_index: usize,
|
||||||
) -> Option<&hir::Ty<'tcx>> {
|
) -> 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(self.mir_hir_id())?;
|
||||||
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
|
|
||||||
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
|
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
|
||||||
match argument_hir_ty.kind {
|
match argument_hir_ty.kind {
|
||||||
// This indicates a variable with no type annotation, like
|
// This indicates a variable with no type annotation, like
|
||||||
@ -649,9 +655,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(return_ty.into(), Some(highlight)).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(self.mir_hir_id()) {
|
||||||
|
|
||||||
let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) {
|
|
||||||
hir::Node::Expr(hir::Expr {
|
hir::Node::Expr(hir::Expr {
|
||||||
kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
|
kind: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
|
||||||
..
|
..
|
||||||
@ -702,9 +706,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
let type_name =
|
let type_name =
|
||||||
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).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(self.mir_hir_id()) {
|
||||||
|
|
||||||
let yield_span = match tcx.hir().get(mir_hir_id) {
|
|
||||||
hir::Node::Expr(hir::Expr {
|
hir::Node::Expr(hir::Expr {
|
||||||
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
|
kind: hir::ExprKind::Closure(_, _, _, span, _), ..
|
||||||
}) => (tcx.sess.source_map().end_point(*span)),
|
}) => (tcx.sess.source_map().end_point(*span)),
|
||||||
|
@ -285,7 +285,6 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
infcx,
|
infcx,
|
||||||
param_env,
|
param_env,
|
||||||
body: promoted_body,
|
body: promoted_body,
|
||||||
mir_def_id: def.did,
|
|
||||||
move_data: &move_data,
|
move_data: &move_data,
|
||||||
location_table: &LocationTable::new(promoted_body),
|
location_table: &LocationTable::new(promoted_body),
|
||||||
movable_generator,
|
movable_generator,
|
||||||
@ -319,7 +318,6 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
infcx,
|
infcx,
|
||||||
param_env,
|
param_env,
|
||||||
body,
|
body,
|
||||||
mir_def_id: def.did,
|
|
||||||
move_data: &mdpe.move_data,
|
move_data: &mdpe.move_data,
|
||||||
location_table,
|
location_table,
|
||||||
movable_generator,
|
movable_generator,
|
||||||
@ -473,7 +471,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
|
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
|
||||||
param_env: ParamEnv<'tcx>,
|
param_env: ParamEnv<'tcx>,
|
||||||
body: &'cx Body<'tcx>,
|
body: &'cx Body<'tcx>,
|
||||||
mir_def_id: LocalDefId,
|
|
||||||
move_data: &'cx MoveData<'tcx>,
|
move_data: &'cx MoveData<'tcx>,
|
||||||
|
|
||||||
/// Map from MIR `Location` to `LocationIndex`; created
|
/// Map from MIR `Location` to `LocationIndex`; created
|
||||||
|
Loading…
x
Reference in New Issue
Block a user