Nits
This commit is contained in:
@@ -4195,7 +4195,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let return_ty = sig.output();
|
let return_ty = sig.output();
|
||||||
match return_ty.skip_binder().kind() {
|
match return_ty.skip_binder().kind() {
|
||||||
ty::Ref(return_region, _, _)
|
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
|
// This is case 1 from above, return type is a named reference so we need to
|
||||||
// search for relevant arguments.
|
// search for relevant arguments.
|
||||||
|
|||||||
@@ -853,7 +853,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let lifetime =
|
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() {
|
let arg = match param.param.pat.simple_ident() {
|
||||||
Some(simple_ident) => format!("argument `{simple_ident}`"),
|
Some(simple_ident) => format!("argument `{simple_ident}`"),
|
||||||
|
|||||||
@@ -2338,7 +2338,7 @@ fn lint_redundant_lifetimes<'tcx>(
|
|||||||
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
|
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.
|
// 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
|
// This makes sure that if `'a = 'b = 'c`, we don't say `'c` should be replaced by
|
||||||
|
|||||||
@@ -578,9 +578,7 @@ fn get_new_lifetime_name<'tcx>(
|
|||||||
let existing_lifetimes = tcx
|
let existing_lifetimes = tcx
|
||||||
.collect_referenced_late_bound_regions(poly_trait_ref)
|
.collect_referenced_late_bound_regions(poly_trait_ref)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|lt| {
|
.filter_map(|lt| lt.get_name(tcx).map(|name| name.as_str().to_string()))
|
||||||
if let Some(name) = lt.get_name(tcx) { Some(name.as_str().to_string()) } else { None }
|
|
||||||
})
|
|
||||||
.chain(generics.params.iter().filter_map(|param| {
|
.chain(generics.params.iter().filter_map(|param| {
|
||||||
if let hir::GenericParamKind::Lifetime { .. } = ¶m.kind {
|
if let hir::GenericParamKind::Lifetime { .. } = ¶m.kind {
|
||||||
Some(param.name.ident().as_str().to_string())
|
Some(param.name.ident().as_str().to_string())
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use rustc_middle::ty::{
|
|||||||
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
||||||
TypeVisitor, Upcast,
|
TypeVisitor, Upcast,
|
||||||
};
|
};
|
||||||
use rustc_span::{ErrorGuaranteed, Ident, Span, kw};
|
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
|
||||||
use rustc_trait_selection::traits;
|
use rustc_trait_selection::traits;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ impl<'tcx> Region<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Is this region named by the user?
|
/// 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() {
|
match self.kind() {
|
||||||
ty::ReEarlyParam(ebr) => ebr.is_named(),
|
ty::ReEarlyParam(ebr) => ebr.is_named(),
|
||||||
ty::ReBound(_, br) => br.kind.is_named(tcx),
|
ty::ReBound(_, br) => br.kind.is_named(tcx),
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
// only introduced anonymous regions in parameters) as well as a
|
// only introduced anonymous regions in parameters) as well as a
|
||||||
// version new_ty of its type where the anonymous region is replaced
|
// version new_ty of its type where the anonymous region is replaced
|
||||||
// with the named one.
|
// 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(region_info) = self.tcx().is_suitable_region(self.generic_param_scope, sup)
|
||||||
&& let Some(anon_param_info) = self.find_param_with_region(sup, sub)
|
&& let Some(anon_param_info) = self.find_param_with_region(sup, sub)
|
||||||
{
|
{
|
||||||
(sub, sup, anon_param_info, region_info)
|
(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(region_info) = self.tcx().is_suitable_region(self.generic_param_scope, sub)
|
||||||
&& let Some(anon_param_info) = self.find_param_with_region(sub, sup)
|
&& 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 scope_def_id = region_info.scope;
|
||||||
let is_impl_item = region_info.is_impl_item;
|
let is_impl_item = region_info.is_impl_item;
|
||||||
|
|
||||||
if !anon_param_info.kind.is_named(self.tcx()) {
|
if anon_param_info.kind.is_named(self.tcx()) {
|
||||||
// Anon region
|
|
||||||
} else {
|
|
||||||
/* not an anonymous region */
|
/* not an anonymous region */
|
||||||
debug!("try_report_named_anon_conflict: not an anonymous region");
|
debug!("try_report_named_anon_conflict: not an anonymous region");
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
sub_region @ Region(Interned(RePlaceholder(_), _)),
|
sub_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
sup_region,
|
sup_region,
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => 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,
|
cause,
|
||||||
Some(*sub_region),
|
Some(*sub_region),
|
||||||
None,
|
None,
|
||||||
@@ -176,7 +176,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
|||||||
sub_region,
|
sub_region,
|
||||||
sup_region @ Region(Interned(RePlaceholder(_), _)),
|
sup_region @ Region(Interned(RePlaceholder(_), _)),
|
||||||
)) => self.try_report_trait_placeholder_mismatch(
|
)) => 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,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(*sup_region),
|
Some(*sup_region),
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
let param = self.find_param_with_region(*sup_r, *sub_r)?;
|
let param = self.find_param_with_region(*sup_r, *sub_r)?;
|
||||||
let simple_ident = param.param.pat.simple_ident();
|
let simple_ident = param.param.pat.simple_ident();
|
||||||
let lifetime_name =
|
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) =
|
let (mention_influencer, influencer_point) =
|
||||||
if sup_origin.span().overlaps(param.param_ty_span) {
|
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`.
|
// 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),
|
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(),
|
lifetime: lifetime_name.clone(),
|
||||||
has_param_name: simple_ident.is_some(),
|
has_param_name: simple_ident.is_some(),
|
||||||
param_name: simple_ident.map(|x| x.to_string()).unwrap_or_default(),
|
param_name: simple_ident.map(|x| x.to_string()).unwrap_or_default(),
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for HighlightBuilder<'tcx> {
|
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for HighlightBuilder<'tcx> {
|
||||||
fn visit_region(&mut self, r: ty::Region<'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.highlight.highlighting_region(r, self.counter);
|
||||||
self.counter += 1;
|
self.counter += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -729,7 +729,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
.dcx()
|
.dcx()
|
||||||
.struct_span_err(span, format!("{labeled_user_string} may not live long enough"));
|
.struct_span_err(span, format!("{labeled_user_string} may not live long enough"));
|
||||||
err.code(match sub.kind() {
|
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,
|
ty::ReStatic => E0310,
|
||||||
_ => E0311,
|
_ => E0311,
|
||||||
});
|
});
|
||||||
@@ -877,7 +877,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
let (lifetime_def_id, lifetime_scope) =
|
let (lifetime_def_id, lifetime_scope) =
|
||||||
match self.tcx.is_suitable_region(generic_param_scope, lifetime) {
|
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)
|
(info.region_def_id.expect_local(), info.scope)
|
||||||
}
|
}
|
||||||
_ => return lifetime.get_name_or_anon(self.tcx).to_string(),
|
_ => return lifetime.get_name_or_anon(self.tcx).to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user