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
|
@ -54,13 +54,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let param = anon_param_info.param;
|
||||
let new_ty = anon_param_info.param_ty;
|
||||
let new_ty_span = anon_param_info.param_ty_span;
|
||||
let br = anon_param_info.br;
|
||||
let is_first = anon_param_info.is_first;
|
||||
let scope_def_id = region_info.scope;
|
||||
let is_impl_item = region_info.is_impl_item;
|
||||
|
||||
match br {
|
||||
ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime) | ty::BoundRegionKind::Anon => {}
|
||||
match anon_param_info.kind {
|
||||
ty::LateParamRegionKind::Named(_, kw::UnderscoreLifetime)
|
||||
| ty::LateParamRegionKind::Anon(_) => {}
|
||||
_ => {
|
||||
/* not an anonymous region */
|
||||
debug!("try_report_named_anon_conflict: not an anonymous region");
|
||||
|
|
|
@ -17,8 +17,8 @@ pub struct AnonymousParamInfo<'tcx> {
|
|||
pub param: &'tcx hir::Param<'tcx>,
|
||||
/// The type corresponding to the anonymous region parameter.
|
||||
pub param_ty: Ty<'tcx>,
|
||||
/// The `ty::BoundRegionKind` corresponding to the anonymous region.
|
||||
pub br: ty::BoundRegionKind,
|
||||
/// The `ty::LateParamRegionKind` corresponding to the anonymous region.
|
||||
pub kind: ty::LateParamRegionKind,
|
||||
/// The `Span` of the parameter type.
|
||||
pub param_ty_span: Span,
|
||||
/// Signals that the argument is the first parameter in the declaration.
|
||||
|
@ -43,11 +43,11 @@ pub fn find_param_with_region<'tcx>(
|
|||
anon_region: Region<'tcx>,
|
||||
replace_region: Region<'tcx>,
|
||||
) -> Option<AnonymousParamInfo<'tcx>> {
|
||||
let (id, br) = match *anon_region {
|
||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
||||
let (id, kind) = match *anon_region {
|
||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.kind),
|
||||
ty::ReEarlyParam(ebr) => {
|
||||
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
||||
(tcx.parent(region_def), ty::BoundRegionKind::Named(region_def, ebr.name))
|
||||
(tcx.parent(region_def), ty::LateParamRegionKind::Named(region_def, ebr.name))
|
||||
}
|
||||
_ => return None, // not a free region
|
||||
};
|
||||
|
@ -96,7 +96,7 @@ pub fn find_param_with_region<'tcx>(
|
|||
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
||||
let param_ty_span = hir.span(ty_hir_id);
|
||||
let is_first = index == 0;
|
||||
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, br, is_first }
|
||||
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1095,13 +1095,13 @@ fn msg_span_from_named_region<'tcx>(
|
|||
(text, Some(span))
|
||||
}
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
if !fr.kind.is_named()
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||
{
|
||||
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
||||
} else {
|
||||
match fr.bound_region {
|
||||
ty::BoundRegionKind::Named(param_def_id, name) => {
|
||||
match fr.kind {
|
||||
ty::LateParamRegionKind::Named(param_def_id, name) => {
|
||||
let span = tcx.def_span(param_def_id);
|
||||
let text = if name == kw::UnderscoreLifetime {
|
||||
"the anonymous lifetime as defined here".to_string()
|
||||
|
@ -1110,7 +1110,7 @@ fn msg_span_from_named_region<'tcx>(
|
|||
};
|
||||
(text, Some(span))
|
||||
}
|
||||
ty::BoundRegionKind::Anon => (
|
||||
ty::LateParamRegionKind::Anon(_) => (
|
||||
"the anonymous lifetime as defined here".to_string(),
|
||||
Some(tcx.def_span(generic_param_scope)),
|
||||
),
|
||||
|
|
|
@ -39,14 +39,14 @@ impl<'a> DescriptionCtx<'a> {
|
|||
}
|
||||
}
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
if !fr.kind.is_named()
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||
{
|
||||
(Some(ty.span), "defined_here", String::new())
|
||||
} else {
|
||||
let scope = fr.scope.expect_local();
|
||||
match fr.bound_region {
|
||||
ty::BoundRegionKind::Named(_, name) => {
|
||||
match fr.kind {
|
||||
ty::LateParamRegionKind::Named(_, name) => {
|
||||
let span = if let Some(param) = tcx
|
||||
.hir()
|
||||
.get_generics(scope)
|
||||
|
@ -62,7 +62,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
(Some(span), "as_defined", name.to_string())
|
||||
}
|
||||
}
|
||||
ty::BoundRegionKind::Anon => {
|
||||
ty::LateParamRegionKind::Anon(_) => {
|
||||
let span = Some(tcx.def_span(scope));
|
||||
(span, "defined_here", String::new())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue