Auto merge of #133961 - lcnr:borrowck-cleanup, r=jackh726
cleanup region handling: add `LateParamRegionKind` The second commit is to enable a split between `BoundRegionKind` and `LateParamRegionKind`, by avoiding `BoundRegionKind` where it isn't necessary. The third comment then adds `LateParamRegionKind` to avoid having the same late-param region for separate bound regions. This fixes #124021. r? `@compiler-errors`
This commit is contained in:
commit
a4079b29bb
23 changed files with 194 additions and 66 deletions
|
@ -430,12 +430,12 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
struct RemapLateBound<'a, 'tcx> {
|
||||
struct RemapLateParam<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
mapping: &'a FxIndexMap<ty::BoundRegionKind, ty::BoundRegionKind>,
|
||||
mapping: &'a FxIndexMap<ty::LateParamRegionKind, ty::LateParamRegionKind>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
|
||||
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'_, 'tcx> {
|
||||
fn cx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
|
|||
ty::Region::new_late_param(
|
||||
self.tcx,
|
||||
fr.scope,
|
||||
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
|
||||
self.mapping.get(&fr.kind).copied().unwrap_or(fr.kind),
|
||||
)
|
||||
} else {
|
||||
r
|
||||
|
|
|
@ -289,11 +289,16 @@ fn report_mismatched_rpitit_signature<'tcx>(
|
|||
tcx.fn_sig(trait_m_def_id).skip_binder().bound_vars(),
|
||||
tcx.fn_sig(impl_m_def_id).skip_binder().bound_vars(),
|
||||
)
|
||||
.filter_map(|(impl_bv, trait_bv)| {
|
||||
.enumerate()
|
||||
.filter_map(|(idx, (impl_bv, trait_bv))| {
|
||||
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
|
||||
&& let ty::BoundVariableKind::Region(trait_bv) = trait_bv
|
||||
{
|
||||
Some((impl_bv, trait_bv))
|
||||
let var = ty::BoundVar::from_usize(idx);
|
||||
Some((
|
||||
ty::LateParamRegionKind::from_bound(var, impl_bv),
|
||||
ty::LateParamRegionKind::from_bound(var, trait_bv),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -301,7 +306,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
|
|||
.collect();
|
||||
|
||||
let mut return_ty =
|
||||
trait_m_sig.output().fold_with(&mut super::RemapLateBound { tcx, mapping: &mapping });
|
||||
trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping: &mapping });
|
||||
|
||||
if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() {
|
||||
let ty::Alias(ty::Projection, future_ty) = return_ty.kind() else {
|
||||
|
|
|
@ -2339,8 +2339,11 @@ fn lint_redundant_lifetimes<'tcx>(
|
|||
);
|
||||
// If we are in a function, add its late-bound lifetimes too.
|
||||
if matches!(def_kind, DefKind::Fn | DefKind::AssocFn) {
|
||||
for var in tcx.fn_sig(owner_id).instantiate_identity().bound_vars() {
|
||||
for (idx, var) in
|
||||
tcx.fn_sig(owner_id).instantiate_identity().bound_vars().iter().enumerate()
|
||||
{
|
||||
let ty::BoundVariableKind::Region(kind) = var else { continue };
|
||||
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
|
||||
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -355,7 +355,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
ty::Region::new_late_param(
|
||||
tcx,
|
||||
scope.to_def_id(),
|
||||
ty::BoundRegionKind::Named(id.to_def_id(), name),
|
||||
ty::LateParamRegionKind::Named(id.to_def_id(), name),
|
||||
)
|
||||
|
||||
// (*) -- not late-bound, won't change
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue