rustc_trait_selection/error_reporting/infer/nice_region_error/
named_anon_conflict.rsuse rustc_errors::Diag;
use rustc_middle::ty;
use rustc_span::kw;
use tracing::debug;
use crate::error_reporting::infer::nice_region_error::NiceRegionError;
use crate::error_reporting::infer::nice_region_error::find_anon_type::find_anon_type;
use crate::errors::ExplicitLifetimeRequired;
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
pub(super) fn try_report_named_anon_conflict(&self) -> Option<Diag<'tcx>> {
let (span, sub, sup) = self.regions()?;
debug!(
"try_report_named_anon_conflict(sub={:?}, sup={:?}, error={:?})",
sub, sup, self.error,
);
let (named, anon, anon_param_info, region_info) = if sub.has_name()
&& let Some(region_info) = self.tcx().is_suitable_region(self.generic_param_scope, sup)
&& let Some(anon_param_info) = self.find_param_with_region(sup, sub)
{
(sub, sup, anon_param_info, region_info)
} else if sup.has_name()
&& let Some(region_info) = self.tcx().is_suitable_region(self.generic_param_scope, sub)
&& let Some(anon_param_info) = self.find_param_with_region(sub, sup)
{
(sup, sub, anon_param_info, region_info)
} else {
return None; };
if named.is_static() {
return None;
}
debug!("try_report_named_anon_conflict: named = {:?}", named);
debug!("try_report_named_anon_conflict: anon_param_info = {:?}", anon_param_info);
debug!("try_report_named_anon_conflict: region_info = {:?}", region_info);
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 is_first = anon_param_info.is_first;
let scope_def_id = region_info.scope;
let is_impl_item = region_info.is_impl_item;
match anon_param_info.kind {
ty::LateParamRegionKind::Named(_, kw::UnderscoreLifetime)
| ty::LateParamRegionKind::Anon(_) => {}
_ => {
debug!("try_report_named_anon_conflict: not an anonymous region");
return None;
}
}
if is_impl_item {
debug!("try_report_named_anon_conflict: impl item, bail out");
return None;
}
if find_anon_type(self.tcx(), self.generic_param_scope, anon).is_some()
&& self.is_self_anon(is_first, scope_def_id)
{
return None;
}
let named = named.to_string();
let err = match param.pat.simple_ident() {
Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
span,
simple_ident,
named,
new_ty_span,
new_ty,
},
None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
};
Some(self.tcx().sess.dcx().create_err(err))
}
}