Rollup merge of #134412 - lcnr:borrowck-cleanup-trivial, r=jackh726
small borrowck cleanup the already approved parts of #133909 and #133961 r? `@jackh726`
This commit is contained in:
commit
cdd71c9f3d
14 changed files with 103 additions and 142 deletions
|
@ -848,7 +848,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
|
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.scope);
|
||||||
|
|
||||||
let param = if let Some(param) =
|
let param = if let Some(param) =
|
||||||
find_param_with_region(self.infcx.tcx, self.mir_def_id(), f, outlived_f)
|
find_param_with_region(self.infcx.tcx, self.mir_def_id(), f, outlived_f)
|
||||||
|
@ -875,7 +875,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
Some(arg),
|
Some(arg),
|
||||||
captures,
|
captures,
|
||||||
Some((param.param_ty_span, param.param_ty.to_string())),
|
Some((param.param_ty_span, param.param_ty.to_string())),
|
||||||
Some(suitable_region.def_id),
|
Some(suitable_region.scope),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -883,7 +883,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
let Some((alias_tys, alias_span, lt_addition_span)) = self
|
let Some((alias_tys, alias_span, lt_addition_span)) = self
|
||||||
.infcx
|
.infcx
|
||||||
.tcx
|
.tcx
|
||||||
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id)
|
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.scope)
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -1018,18 +1018,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some((ty_sub, _)) =
|
let Some((ty_sub, _)) = self
|
||||||
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sub).and_then(|anon_reg| {
|
.infcx
|
||||||
find_anon_type(self.infcx.tcx, self.mir_def_id(), sub, &anon_reg.bound_region)
|
.tcx
|
||||||
})
|
.is_suitable_region(self.mir_def_id(), sub)
|
||||||
|
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sub))
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some((ty_sup, _)) =
|
let Some((ty_sup, _)) = self
|
||||||
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sup).and_then(|anon_reg| {
|
.infcx
|
||||||
find_anon_type(self.infcx.tcx, self.mir_def_id(), sup, &anon_reg.bound_region)
|
.tcx
|
||||||
})
|
.is_suitable_region(self.mir_def_id(), sup)
|
||||||
|
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sup))
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
@ -141,6 +141,9 @@ fn do_mir_borrowck<'tcx>(
|
||||||
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
||||||
let def = input_body.source.def_id().expect_local();
|
let def = input_body.source.def_id().expect_local();
|
||||||
let infcx = BorrowckInferCtxt::new(tcx, def);
|
let infcx = BorrowckInferCtxt::new(tcx, def);
|
||||||
|
if let Some(e) = input_body.tainted_by_errors {
|
||||||
|
infcx.set_tainted_by_errors(e);
|
||||||
|
}
|
||||||
|
|
||||||
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
||||||
for var_debug_info in &input_body.var_debug_info {
|
for var_debug_info in &input_body.var_debug_info {
|
||||||
|
@ -162,13 +165,6 @@ fn do_mir_borrowck<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let diags = &mut diags::BorrowckDiags::new();
|
|
||||||
|
|
||||||
// Gather the upvars of a closure, if any.
|
|
||||||
if let Some(e) = input_body.tainted_by_errors {
|
|
||||||
infcx.set_tainted_by_errors(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace all regions with fresh inference variables. This
|
// Replace all regions with fresh inference variables. This
|
||||||
// requires first making our own copy of the MIR. This copy will
|
// requires first making our own copy of the MIR. This copy will
|
||||||
// be modified (in place) to contain non-lexical lifetimes. It
|
// be modified (in place) to contain non-lexical lifetimes. It
|
||||||
|
@ -224,6 +220,7 @@ fn do_mir_borrowck<'tcx>(
|
||||||
|
|
||||||
// We also have a `#[rustc_regions]` annotation that causes us to dump
|
// We also have a `#[rustc_regions]` annotation that causes us to dump
|
||||||
// information.
|
// information.
|
||||||
|
let diags = &mut diags::BorrowckDiags::new();
|
||||||
nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, &opaque_type_values, diags);
|
nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, &opaque_type_values, diags);
|
||||||
|
|
||||||
let movable_coroutine =
|
let movable_coroutine =
|
||||||
|
|
|
@ -689,7 +689,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
/// Require that the region `r` be equal to one of the regions in
|
/// Require that the region `r` be equal to one of the regions in
|
||||||
/// the set `regions`.
|
/// the set `regions`.
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn member_constraint(
|
pub fn add_member_constraint(
|
||||||
&self,
|
&self,
|
||||||
key: ty::OpaqueTypeKey<'tcx>,
|
key: ty::OpaqueTypeKey<'tcx>,
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
|
@ -697,7 +697,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
|
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
|
||||||
) {
|
) {
|
||||||
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
|
self.inner.borrow_mut().unwrap_region_constraints().add_member_constraint(
|
||||||
key,
|
key,
|
||||||
definition_span,
|
definition_span,
|
||||||
hidden_ty,
|
hidden_ty,
|
||||||
|
|
|
@ -364,7 +364,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
op: |r| {
|
op: |r| {
|
||||||
self.member_constraint(
|
self.add_member_constraint(
|
||||||
opaque_type_key,
|
opaque_type_key,
|
||||||
span,
|
span,
|
||||||
concrete_ty,
|
concrete_ty,
|
||||||
|
|
|
@ -466,7 +466,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn member_constraint(
|
pub(super) fn add_member_constraint(
|
||||||
&mut self,
|
&mut self,
|
||||||
key: ty::OpaqueTypeKey<'tcx>,
|
key: ty::OpaqueTypeKey<'tcx>,
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
|
|
|
@ -1119,10 +1119,10 @@ impl<'tcx> CommonConsts<'tcx> {
|
||||||
/// either a `ReEarlyParam` or `ReLateParam`.
|
/// either a `ReEarlyParam` or `ReLateParam`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FreeRegionInfo {
|
pub struct FreeRegionInfo {
|
||||||
/// `LocalDefId` of the free region.
|
/// `LocalDefId` of the scope.
|
||||||
pub def_id: LocalDefId,
|
pub scope: LocalDefId,
|
||||||
/// the bound region corresponding to free region.
|
/// the `DefId` of the free region.
|
||||||
pub bound_region: ty::BoundRegionKind,
|
pub region_def_id: DefId,
|
||||||
/// checks if bound region is in Impl Item
|
/// checks if bound region is in Impl Item
|
||||||
pub is_impl_item: bool,
|
pub is_impl_item: bool,
|
||||||
}
|
}
|
||||||
|
@ -1960,7 +1960,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
generic_param_scope: LocalDefId,
|
generic_param_scope: LocalDefId,
|
||||||
mut region: Region<'tcx>,
|
mut region: Region<'tcx>,
|
||||||
) -> Option<FreeRegionInfo> {
|
) -> Option<FreeRegionInfo> {
|
||||||
let (suitable_region_binding_scope, bound_region) = loop {
|
let (suitable_region_binding_scope, region_def_id) = loop {
|
||||||
let def_id =
|
let def_id =
|
||||||
region.opt_param_def_id(self, generic_param_scope.to_def_id())?.as_local()?;
|
region.opt_param_def_id(self, generic_param_scope.to_def_id())?.as_local()?;
|
||||||
let scope = self.local_parent(def_id);
|
let scope = self.local_parent(def_id);
|
||||||
|
@ -1970,10 +1970,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
region = self.map_opaque_lifetime_to_parent_lifetime(def_id);
|
region = self.map_opaque_lifetime_to_parent_lifetime(def_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break (
|
break (scope, def_id.into());
|
||||||
scope,
|
|
||||||
ty::BoundRegionKind::Named(def_id.into(), self.item_name(def_id.into())),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
|
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
|
||||||
|
@ -1982,7 +1979,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(FreeRegionInfo { def_id: suitable_region_binding_scope, bound_region, is_impl_item })
|
Some(FreeRegionInfo { scope: suitable_region_binding_scope, region_def_id, is_impl_item })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
||||||
|
|
|
@ -63,26 +63,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the sub and sup consist of both anonymous (elided) regions.
|
// Determine whether the sub and sup consist of both anonymous (elided) regions.
|
||||||
let anon_reg_sup = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
|
let sup_info = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
|
||||||
|
|
||||||
let anon_reg_sub = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
|
let sub_info = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
|
||||||
let scope_def_id_sup = anon_reg_sup.def_id;
|
|
||||||
let bregion_sup = anon_reg_sup.bound_region;
|
|
||||||
let scope_def_id_sub = anon_reg_sub.def_id;
|
|
||||||
let bregion_sub = anon_reg_sub.bound_region;
|
|
||||||
|
|
||||||
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup, &bregion_sup)?;
|
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup)?;
|
||||||
|
|
||||||
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub, &bregion_sub)?;
|
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub)?;
|
||||||
|
|
||||||
debug!(
|
debug!("try_report_anon_anon_conflict: found_param1={:?} sup={:?}", ty_sub, sup);
|
||||||
"try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}",
|
debug!("try_report_anon_anon_conflict: found_param2={:?} sub={:?}", ty_sup, sub);
|
||||||
ty_sub, sup, bregion_sup
|
|
||||||
);
|
|
||||||
debug!(
|
|
||||||
"try_report_anon_anon_conflict: found_param2={:?} sub={:?} br2={:?}",
|
|
||||||
ty_sup, sub, bregion_sub
|
|
||||||
);
|
|
||||||
|
|
||||||
let (ty_sup, ty_fndecl_sup) = ty_sup;
|
let (ty_sup, ty_fndecl_sup) = ty_sup;
|
||||||
let (ty_sub, ty_fndecl_sub) = ty_sub;
|
let (ty_sub, ty_fndecl_sub) = ty_sub;
|
||||||
|
@ -93,9 +83,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
self.find_param_with_region(sub, sub)?;
|
self.find_param_with_region(sub, sub)?;
|
||||||
|
|
||||||
let sup_is_ret_type =
|
let sup_is_ret_type =
|
||||||
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
|
self.is_return_type_anon(sup_info.scope, sup_info.region_def_id, ty_fndecl_sup);
|
||||||
let sub_is_ret_type =
|
let sub_is_ret_type =
|
||||||
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
|
self.is_return_type_anon(sub_info.scope, sub_info.region_def_id, ty_fndecl_sub);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}",
|
"try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use core::ops::ControlFlow;
|
use core::ops::ControlFlow;
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
|
@ -28,16 +28,15 @@ pub fn find_anon_type<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
generic_param_scope: LocalDefId,
|
generic_param_scope: LocalDefId,
|
||||||
region: Region<'tcx>,
|
region: Region<'tcx>,
|
||||||
br: &ty::BoundRegionKind,
|
|
||||||
) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> {
|
) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> {
|
||||||
let anon_reg = tcx.is_suitable_region(generic_param_scope, region)?;
|
let anon_reg = tcx.is_suitable_region(generic_param_scope, region)?;
|
||||||
let fn_sig = tcx.hir_node_by_def_id(anon_reg.def_id).fn_sig()?;
|
let fn_sig = tcx.hir_node_by_def_id(anon_reg.scope).fn_sig()?;
|
||||||
|
|
||||||
fn_sig
|
fn_sig
|
||||||
.decl
|
.decl
|
||||||
.inputs
|
.inputs
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|arg| find_component_for_bound_region(tcx, arg, br))
|
.find_map(|arg| find_component_for_bound_region(tcx, arg, anon_reg.region_def_id))
|
||||||
.map(|ty| (ty, fn_sig))
|
.map(|ty| (ty, fn_sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +45,9 @@ pub fn find_anon_type<'tcx>(
|
||||||
fn find_component_for_bound_region<'tcx>(
|
fn find_component_for_bound_region<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
arg: &'tcx hir::Ty<'tcx>,
|
arg: &'tcx hir::Ty<'tcx>,
|
||||||
br: &ty::BoundRegionKind,
|
region_def_id: DefId,
|
||||||
) -> Option<&'tcx hir::Ty<'tcx>> {
|
) -> Option<&'tcx hir::Ty<'tcx>> {
|
||||||
FindNestedTypeVisitor { tcx, bound_region: *br, current_index: ty::INNERMOST }
|
FindNestedTypeVisitor { tcx, region_def_id, current_index: ty::INNERMOST }
|
||||||
.visit_ty(arg)
|
.visit_ty(arg)
|
||||||
.break_value()
|
.break_value()
|
||||||
}
|
}
|
||||||
|
@ -62,9 +61,8 @@ fn find_component_for_bound_region<'tcx>(
|
||||||
// specific part of the type in the error message.
|
// specific part of the type in the error message.
|
||||||
struct FindNestedTypeVisitor<'tcx> {
|
struct FindNestedTypeVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
// The bound_region corresponding to the Refree(freeregion)
|
// The `DefId` of the region we're looking for.
|
||||||
// associated with the anonymous region we are looking for.
|
region_def_id: DefId,
|
||||||
bound_region: ty::BoundRegionKind,
|
|
||||||
current_index: ty::DebruijnIndex,
|
current_index: ty::DebruijnIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,16 +94,13 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
||||||
hir::TyKind::Ref(lifetime, _) => {
|
hir::TyKind::Ref(lifetime, _) => {
|
||||||
// the lifetime of the Ref
|
// the lifetime of the Ref
|
||||||
let hir_id = lifetime.hir_id;
|
let hir_id = lifetime.hir_id;
|
||||||
match (self.tcx.named_bound_var(hir_id), self.bound_region) {
|
match self.tcx.named_bound_var(hir_id) {
|
||||||
// Find the index of the named region that was part of the
|
// Find the index of the named region that was part of the
|
||||||
// error. We will then search the function parameters for a bound
|
// error. We will then search the function parameters for a bound
|
||||||
// region at the right depth with the same index
|
// region at the right depth with the same index
|
||||||
(
|
Some(rbv::ResolvedArg::EarlyBound(id)) => {
|
||||||
Some(rbv::ResolvedArg::EarlyBound(id)),
|
debug!("EarlyBound id={:?}", id);
|
||||||
ty::BoundRegionKind::Named(def_id, _),
|
if id.to_def_id() == self.region_def_id {
|
||||||
) => {
|
|
||||||
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
|
|
||||||
if id.to_def_id() == def_id {
|
|
||||||
return ControlFlow::Break(arg);
|
return ControlFlow::Break(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,31 +108,25 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
||||||
// Find the index of the named region that was part of the
|
// Find the index of the named region that was part of the
|
||||||
// error. We will then search the function parameters for a bound
|
// error. We will then search the function parameters for a bound
|
||||||
// region at the right depth with the same index
|
// region at the right depth with the same index
|
||||||
(
|
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
|
||||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
|
|
||||||
ty::BoundRegionKind::Named(def_id, _),
|
|
||||||
) => {
|
|
||||||
debug!(
|
debug!(
|
||||||
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
|
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
|
||||||
debruijn_index
|
debruijn_index
|
||||||
);
|
);
|
||||||
debug!("LateBound id={:?} def_id={:?}", id, def_id);
|
debug!("LateBound id={:?}", id);
|
||||||
if debruijn_index == self.current_index && id.to_def_id() == def_id {
|
if debruijn_index == self.current_index
|
||||||
|
&& id.to_def_id() == self.region_def_id
|
||||||
|
{
|
||||||
return ControlFlow::Break(arg);
|
return ControlFlow::Break(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
|
||||||
Some(
|
Some(
|
||||||
rbv::ResolvedArg::StaticLifetime
|
rbv::ResolvedArg::StaticLifetime
|
||||||
| rbv::ResolvedArg::Free(_, _)
|
| rbv::ResolvedArg::Free(_, _)
|
||||||
| rbv::ResolvedArg::EarlyBound(_)
|
|
||||||
| rbv::ResolvedArg::LateBound(_, _, _)
|
|
||||||
| rbv::ResolvedArg::Error(_),
|
| rbv::ResolvedArg::Error(_),
|
||||||
)
|
)
|
||||||
| None,
|
| None => {
|
||||||
_,
|
|
||||||
) => {
|
|
||||||
debug!("no arg found");
|
debug!("no arg found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +140,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
||||||
return if intravisit::walk_ty(
|
return if intravisit::walk_ty(
|
||||||
&mut TyPathVisitor {
|
&mut TyPathVisitor {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
bound_region: self.bound_region,
|
region_def_id: self.region_def_id,
|
||||||
current_index: self.current_index,
|
current_index: self.current_index,
|
||||||
},
|
},
|
||||||
arg,
|
arg,
|
||||||
|
@ -179,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
||||||
// specific part of the type in the error message.
|
// specific part of the type in the error message.
|
||||||
struct TyPathVisitor<'tcx> {
|
struct TyPathVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
bound_region: ty::BoundRegionKind,
|
region_def_id: DefId,
|
||||||
current_index: ty::DebruijnIndex,
|
current_index: ty::DebruijnIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,38 +181,29 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result {
|
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result {
|
||||||
match (self.tcx.named_bound_var(lifetime.hir_id), self.bound_region) {
|
match self.tcx.named_bound_var(lifetime.hir_id) {
|
||||||
// the lifetime of the TyPath!
|
// the lifetime of the TyPath!
|
||||||
(Some(rbv::ResolvedArg::EarlyBound(id)), ty::BoundRegionKind::Named(def_id, _)) => {
|
Some(rbv::ResolvedArg::EarlyBound(id)) => {
|
||||||
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
|
debug!("EarlyBound id={:?}", id);
|
||||||
if id.to_def_id() == def_id {
|
if id.to_def_id() == self.region_def_id {
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
|
||||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
|
|
||||||
ty::BoundRegionKind::Named(def_id, _),
|
|
||||||
) => {
|
|
||||||
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
|
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
|
||||||
debug!("id={:?}", id);
|
debug!("id={:?}", id);
|
||||||
debug!("def_id={:?}", def_id);
|
if debruijn_index == self.current_index && id.to_def_id() == self.region_def_id {
|
||||||
if debruijn_index == self.current_index && id.to_def_id() == def_id {
|
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
|
||||||
Some(
|
Some(
|
||||||
rbv::ResolvedArg::StaticLifetime
|
rbv::ResolvedArg::StaticLifetime
|
||||||
| rbv::ResolvedArg::EarlyBound(_)
|
|
||||||
| rbv::ResolvedArg::LateBound(_, _, _)
|
|
||||||
| rbv::ResolvedArg::Free(_, _)
|
| rbv::ResolvedArg::Free(_, _)
|
||||||
| rbv::ResolvedArg::Error(_),
|
| rbv::ResolvedArg::Error(_),
|
||||||
)
|
)
|
||||||
| None,
|
| None => {
|
||||||
_,
|
|
||||||
) => {
|
|
||||||
debug!("no arg found");
|
debug!("no arg found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
let param = anon_param_info.param;
|
let param = anon_param_info.param;
|
||||||
let new_ty = anon_param_info.param_ty;
|
let new_ty = anon_param_info.param_ty;
|
||||||
let new_ty_span = anon_param_info.param_ty_span;
|
let new_ty_span = anon_param_info.param_ty_span;
|
||||||
let br = anon_param_info.bound_region;
|
let br = anon_param_info.br;
|
||||||
let is_first = anon_param_info.is_first;
|
let is_first = anon_param_info.is_first;
|
||||||
let scope_def_id = region_info.def_id;
|
let scope_def_id = region_info.scope;
|
||||||
let is_impl_item = region_info.is_impl_item;
|
let is_impl_item = region_info.is_impl_item;
|
||||||
|
|
||||||
match br {
|
match br {
|
||||||
|
@ -73,7 +73,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if find_anon_type(self.tcx(), self.generic_param_scope, anon, &br).is_some()
|
if find_anon_type(self.tcx(), self.generic_param_scope, anon).is_some()
|
||||||
&& self.is_self_anon(is_first, scope_def_id)
|
&& self.is_self_anon(is_first, scope_def_id)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
// This may have a closure and it would cause ICE
|
// This may have a closure and it would cause ICE
|
||||||
// through `find_param_with_region` (#78262).
|
// through `find_param_with_region` (#78262).
|
||||||
let anon_reg_sup = tcx.is_suitable_region(self.generic_param_scope, *sup_r)?;
|
let anon_reg_sup = tcx.is_suitable_region(self.generic_param_scope, *sup_r)?;
|
||||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.scope);
|
||||||
if fn_returns.is_empty() {
|
if fn_returns.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
|
|
||||||
let mut err = self.tcx().dcx().create_err(diag);
|
let mut err = self.tcx().dcx().create_err(diag);
|
||||||
|
|
||||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.scope);
|
||||||
|
|
||||||
let mut override_error_code = None;
|
let mut override_error_code = None;
|
||||||
if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sup_origin
|
if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sup_origin
|
||||||
|
@ -250,7 +250,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
Some(arg),
|
Some(arg),
|
||||||
captures,
|
captures,
|
||||||
Some((param.param_ty_span, param.param_ty.to_string())),
|
Some((param.param_ty_span, param.param_ty.to_string())),
|
||||||
Some(anon_reg_sup.def_id),
|
Some(anon_reg_sup.scope),
|
||||||
);
|
);
|
||||||
|
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! anonymous regions.
|
//! anonymous regions.
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::ty::fold::fold_regions;
|
use rustc_middle::ty::fold::fold_regions;
|
||||||
use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -17,8 +17,8 @@ pub struct AnonymousParamInfo<'tcx> {
|
||||||
pub param: &'tcx hir::Param<'tcx>,
|
pub param: &'tcx hir::Param<'tcx>,
|
||||||
/// The type corresponding to the anonymous region parameter.
|
/// The type corresponding to the anonymous region parameter.
|
||||||
pub param_ty: Ty<'tcx>,
|
pub param_ty: Ty<'tcx>,
|
||||||
/// The ty::BoundRegionKind corresponding to the anonymous region.
|
/// The `ty::BoundRegionKind` corresponding to the anonymous region.
|
||||||
pub bound_region: ty::BoundRegionKind,
|
pub br: ty::BoundRegionKind,
|
||||||
/// The `Span` of the parameter type.
|
/// The `Span` of the parameter type.
|
||||||
pub param_ty_span: Span,
|
pub param_ty_span: Span,
|
||||||
/// Signals that the argument is the first parameter in the declaration.
|
/// Signals that the argument is the first parameter in the declaration.
|
||||||
|
@ -43,7 +43,7 @@ pub fn find_param_with_region<'tcx>(
|
||||||
anon_region: Region<'tcx>,
|
anon_region: Region<'tcx>,
|
||||||
replace_region: Region<'tcx>,
|
replace_region: Region<'tcx>,
|
||||||
) -> Option<AnonymousParamInfo<'tcx>> {
|
) -> Option<AnonymousParamInfo<'tcx>> {
|
||||||
let (id, bound_region) = match *anon_region {
|
let (id, br) = match *anon_region {
|
||||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
||||||
ty::ReEarlyParam(ebr) => {
|
ty::ReEarlyParam(ebr) => {
|
||||||
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
||||||
|
@ -96,13 +96,7 @@ pub fn find_param_with_region<'tcx>(
|
||||||
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
||||||
let param_ty_span = hir.span(ty_hir_id);
|
let param_ty_span = hir.span(ty_hir_id);
|
||||||
let is_first = index == 0;
|
let is_first = index == 0;
|
||||||
AnonymousParamInfo {
|
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, br, is_first }
|
||||||
param,
|
|
||||||
param_ty: new_param_ty,
|
|
||||||
param_ty_span,
|
|
||||||
bound_region,
|
|
||||||
is_first,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -122,7 +116,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
pub(super) fn is_return_type_anon(
|
pub(super) fn is_return_type_anon(
|
||||||
&self,
|
&self,
|
||||||
scope_def_id: LocalDefId,
|
scope_def_id: LocalDefId,
|
||||||
br: ty::BoundRegionKind,
|
region_def_id: DefId,
|
||||||
hir_sig: &hir::FnSig<'_>,
|
hir_sig: &hir::FnSig<'_>,
|
||||||
) -> Option<Span> {
|
) -> Option<Span> {
|
||||||
let fn_ty = self.tcx().type_of(scope_def_id).instantiate_identity();
|
let fn_ty = self.tcx().type_of(scope_def_id).instantiate_identity();
|
||||||
|
@ -135,8 +129,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
return match future_output {
|
return match future_output {
|
||||||
Some(output) if self.includes_region(output, br) => Some(span),
|
Some(output) if self.includes_region(output, region_def_id) => Some(span),
|
||||||
None if self.includes_region(ret_ty, br) => Some(span),
|
None if self.includes_region(ret_ty, region_def_id) => Some(span),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -146,12 +140,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
fn includes_region(
|
fn includes_region(
|
||||||
&self,
|
&self,
|
||||||
ty: Binder<'tcx, impl TypeFoldable<TyCtxt<'tcx>>>,
|
ty: Binder<'tcx, impl TypeFoldable<TyCtxt<'tcx>>>,
|
||||||
region: ty::BoundRegionKind,
|
region_def_id: DefId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(ty);
|
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(ty);
|
||||||
// We are only checking is any region meets the condition so order doesn't matter
|
// We are only checking is any region meets the condition so order doesn't matter
|
||||||
#[allow(rustc::potential_query_instability)]
|
#[allow(rustc::potential_query_instability)]
|
||||||
late_bound_regions.iter().any(|r| *r == region)
|
late_bound_regions.iter().any(|r| match *r {
|
||||||
|
ty::BoundRegionKind::Named(def_id, _) => def_id == region_def_id,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we check for the case where anonymous region
|
// Here we check for the case where anonymous region
|
||||||
|
|
|
@ -790,7 +790,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
let lifetime_scope = match sub.kind() {
|
let lifetime_scope = match sub.kind() {
|
||||||
ty::ReStatic => hir::def_id::CRATE_DEF_ID,
|
ty::ReStatic => hir::def_id::CRATE_DEF_ID,
|
||||||
_ => match self.tcx.is_suitable_region(generic_param_scope, sub) {
|
_ => match self.tcx.is_suitable_region(generic_param_scope, sub) {
|
||||||
Some(info) => info.def_id,
|
Some(info) => info.scope,
|
||||||
None => generic_param_scope,
|
None => generic_param_scope,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -864,11 +864,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (lifetime_def_id, lifetime_scope) =
|
let (lifetime_def_id, lifetime_scope) = match self
|
||||||
match self.tcx.is_suitable_region(generic_param_scope, lifetime) {
|
.tcx
|
||||||
Some(info) if !lifetime.has_name() => {
|
.is_suitable_region(generic_param_scope, lifetime)
|
||||||
(info.bound_region.get_id().unwrap().expect_local(), info.def_id)
|
{
|
||||||
}
|
Some(info) if !lifetime.has_name() => (info.region_def_id.expect_local(), info.scope),
|
||||||
_ => return lifetime.get_name_or_anon().to_string(),
|
_ => return lifetime.get_name_or_anon().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1097,8 +1097,7 @@ fn msg_span_from_named_region<'tcx>(
|
||||||
}
|
}
|
||||||
ty::ReLateParam(ref fr) => {
|
ty::ReLateParam(ref fr) => {
|
||||||
if !fr.bound_region.is_named()
|
if !fr.bound_region.is_named()
|
||||||
&& let Some((ty, _)) =
|
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||||
find_anon_type(tcx, generic_param_scope, region, &fr.bound_region)
|
|
||||||
{
|
{
|
||||||
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -517,7 +517,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let node = self.tcx.hir_node_by_def_id(anon_reg.def_id);
|
let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
|
||||||
let is_impl = matches!(&node, hir::Node::ImplItem(_));
|
let is_impl = matches!(&node, hir::Node::ImplItem(_));
|
||||||
let (generics, parent_generics) = match node {
|
let (generics, parent_generics) = match node {
|
||||||
hir::Node::Item(&hir::Item {
|
hir::Node::Item(&hir::Item {
|
||||||
|
@ -527,7 +527,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
||||||
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. })
|
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. })
|
||||||
| hir::Node::ImplItem(&hir::ImplItem { ref generics, .. }) => (
|
| hir::Node::ImplItem(&hir::ImplItem { ref generics, .. }) => (
|
||||||
generics,
|
generics,
|
||||||
match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.def_id))
|
match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
|
||||||
{
|
{
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Trait(_, _, ref generics, ..),
|
kind: hir::ItemKind::Trait(_, _, ref generics, ..),
|
||||||
|
|
|
@ -41,8 +41,7 @@ impl<'a> DescriptionCtx<'a> {
|
||||||
}
|
}
|
||||||
ty::ReLateParam(ref fr) => {
|
ty::ReLateParam(ref fr) => {
|
||||||
if !fr.bound_region.is_named()
|
if !fr.bound_region.is_named()
|
||||||
&& let Some((ty, _)) =
|
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||||
find_anon_type(tcx, generic_param_scope, region, &fr.bound_region)
|
|
||||||
{
|
{
|
||||||
(Some(ty.span), "defined_here", String::new())
|
(Some(ty.span), "defined_here", String::new())
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue