This commit is contained in:
Michael Goulet
2025-07-04 18:09:11 +00:00
parent 0ad96c1e1f
commit dc8cac8e8d
11 changed files with 16 additions and 20 deletions

View File

@@ -4195,7 +4195,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let return_ty = sig.output();
match return_ty.skip_binder().kind() {
ty::Ref(return_region, _, _)
if return_region.has_name(self.infcx.tcx) && !is_closure =>
if return_region.is_named(self.infcx.tcx) && !is_closure =>
{
// This is case 1 from above, return type is a named reference so we need to
// search for relevant arguments.

View File

@@ -853,7 +853,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
};
let lifetime =
if f.has_name(self.infcx.tcx) { fr_name.name } else { kw::UnderscoreLifetime };
if f.is_named(self.infcx.tcx) { fr_name.name } else { kw::UnderscoreLifetime };
let arg = match param.param.pat.simple_ident() {
Some(simple_ident) => format!("argument `{simple_ident}`"),

View File

@@ -2338,7 +2338,7 @@ fn lint_redundant_lifetimes<'tcx>(
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
}
}
lifetimes.retain(|candidate| candidate.has_name(tcx));
lifetimes.retain(|candidate| candidate.is_named(tcx));
// Keep track of lifetimes which have already been replaced with other lifetimes.
// This makes sure that if `'a = 'b = 'c`, we don't say `'c` should be replaced by

View File

@@ -578,9 +578,7 @@ fn get_new_lifetime_name<'tcx>(
let existing_lifetimes = tcx
.collect_referenced_late_bound_regions(poly_trait_ref)
.into_iter()
.filter_map(|lt| {
if let Some(name) = lt.get_name(tcx) { Some(name.as_str().to_string()) } else { None }
})
.filter_map(|lt| lt.get_name(tcx).map(|name| name.as_str().to_string()))
.chain(generics.params.iter().filter_map(|param| {
if let hir::GenericParamKind::Lifetime { .. } = &param.kind {
Some(param.name.ident().as_str().to_string())

View File

@@ -12,7 +12,7 @@ use rustc_middle::ty::{
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor, Upcast,
};
use rustc_span::{ErrorGuaranteed, Ident, Span, kw};
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
use rustc_trait_selection::traits;
use smallvec::SmallVec;
use tracing::{debug, instrument};

View File

@@ -182,7 +182,7 @@ impl<'tcx> Region<'tcx> {
}
/// Is this region named by the user?
pub fn has_name(self, tcx: TyCtxt<'tcx>) -> bool {
pub fn is_named(self, tcx: TyCtxt<'tcx>) -> bool {
match self.kind() {
ty::ReEarlyParam(ebr) => ebr.is_named(),
ty::ReBound(_, br) => br.kind.is_named(tcx),

View File

@@ -25,12 +25,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// only introduced anonymous regions in parameters) as well as a
// version new_ty of its type where the anonymous region is replaced
// with the named one.
let (named, anon, anon_param_info, region_info) = if sub.has_name(self.tcx())
let (named, anon, anon_param_info, region_info) = if sub.is_named(self.tcx())
&& 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(self.tcx())
} else if sup.is_named(self.tcx())
&& 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)
{
@@ -56,9 +56,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let scope_def_id = region_info.scope;
let is_impl_item = region_info.is_impl_item;
if !anon_param_info.kind.is_named(self.tcx()) {
// Anon region
} else {
if anon_param_info.kind.is_named(self.tcx()) {
/* not an anonymous region */
debug!("try_report_named_anon_conflict: not an anonymous region");
return None;

View File

@@ -164,7 +164,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sub_region @ Region(Interned(RePlaceholder(_), _)),
sup_region,
)) => self.try_report_trait_placeholder_mismatch(
(!sup_region.has_name(self.tcx())).then_some(*sup_region),
(!sup_region.is_named(self.tcx())).then_some(*sup_region),
cause,
Some(*sub_region),
None,
@@ -176,7 +176,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sub_region,
sup_region @ Region(Interned(RePlaceholder(_), _)),
)) => self.try_report_trait_placeholder_mismatch(
(!sub_region.has_name(self.tcx())).then_some(*sub_region),
(!sub_region.is_named(self.tcx())).then_some(*sub_region),
cause,
None,
Some(*sup_region),

View File

@@ -46,7 +46,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let param = self.find_param_with_region(*sup_r, *sub_r)?;
let simple_ident = param.param.pat.simple_ident();
let lifetime_name =
if sup_r.has_name(self.tcx()) { sup_r.to_string() } else { "'_".to_owned() };
if sup_r.is_named(self.tcx()) { sup_r.to_string() } else { "'_".to_owned() };
let (mention_influencer, influencer_point) =
if sup_origin.span().overlaps(param.param_ty_span) {
@@ -100,7 +100,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// We don't need a note, it's already at the end, it can be shown as a `span_label`.
require_span_as_label: (!require_as_note).then_some(require_span),
has_lifetime: sup_r.has_name(self.tcx()),
has_lifetime: sup_r.is_named(self.tcx()),
lifetime: lifetime_name.clone(),
has_param_name: simple_ident.is_some(),
param_name: simple_ident.map(|x| x.to_string()).unwrap_or_default(),

View File

@@ -76,7 +76,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for HighlightBuilder<'tcx> {
fn visit_region(&mut self, r: ty::Region<'tcx>) {
if !r.has_name(self.tcx) && self.counter <= 3 {
if !r.is_named(self.tcx) && self.counter <= 3 {
self.highlight.highlighting_region(r, self.counter);
self.counter += 1;
}

View File

@@ -729,7 +729,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.dcx()
.struct_span_err(span, format!("{labeled_user_string} may not live long enough"));
err.code(match sub.kind() {
ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.has_name(self.tcx) => E0309,
ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.is_named(self.tcx) => E0309,
ty::ReStatic => E0310,
_ => E0311,
});
@@ -877,7 +877,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let (lifetime_def_id, lifetime_scope) =
match self.tcx.is_suitable_region(generic_param_scope, lifetime) {
Some(info) if !lifetime.has_name(self.tcx) => {
Some(info) if !lifetime.is_named(self.tcx) => {
(info.region_def_id.expect_local(), info.scope)
}
_ => return lifetime.get_name_or_anon(self.tcx).to_string(),