-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove kw::Empty
uses from hir::Lifetime::ident
#138965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4924e0a
c6d8d65
cfd00f9
8d2c63f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use rustc_errors::{ | |
use rustc_hir::def::DefKind; | ||
use rustc_hir::def_id::{DefId, LocalDefId}; | ||
use rustc_hir::intravisit::{Visitor, VisitorExt, walk_ty}; | ||
use rustc_hir::{self as hir, AmbigArg, FnRetTy, GenericParamKind, Node}; | ||
use rustc_hir::{self as hir, AmbigArg, FnRetTy, GenericParamKind, IsAnonInPath, Node}; | ||
use rustc_macros::{Diagnostic, Subdiagnostic}; | ||
use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath}; | ||
use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, Region, Ty, TyCtxt}; | ||
|
@@ -567,10 +567,14 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { | |
|
||
impl<'v> Visitor<'v> for ImplicitLifetimeFinder { | ||
fn visit_ty(&mut self, ty: &'v hir::Ty<'v, AmbigArg>) { | ||
let make_suggestion = |ident: Ident| { | ||
if ident.name == kw::Empty && ident.span.is_empty() { | ||
let make_suggestion = |lifetime: &hir::Lifetime| { | ||
if lifetime.is_anon_in_path == IsAnonInPath::Yes | ||
&& lifetime.ident.span.is_empty() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when is this part of the condition ever false. I would expect all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
However, none of those non-empty spans reach here, at least when running the UI tests. (I checked by adding an assertion.) I don't know if that's guaranteed, or if we just have insufficient test coverage. So I'd prefer to keep the test here for now; it is retained from the original code. |
||
{ | ||
format!("{}, ", self.suggestion_param_name) | ||
} else if ident.name == kw::UnderscoreLifetime && ident.span.is_empty() { | ||
} else if lifetime.ident.name == kw::UnderscoreLifetime | ||
&& lifetime.ident.span.is_empty() | ||
Comment on lines
+575
to
+576
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is where changing |
||
{ | ||
format!("{} ", self.suggestion_param_name) | ||
} else { | ||
self.suggestion_param_name.clone() | ||
|
@@ -584,7 +588,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { | |
matches!( | ||
arg, | ||
hir::GenericArg::Lifetime(lifetime) | ||
if lifetime.ident.name == kw::Empty | ||
if lifetime.is_anon_in_path == IsAnonInPath::Yes | ||
) | ||
}) { | ||
self.suggestions.push(( | ||
|
@@ -605,7 +609,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { | |
{ | ||
self.suggestions.push(( | ||
lifetime.ident.span, | ||
make_suggestion(lifetime.ident), | ||
make_suggestion(lifetime), | ||
)); | ||
} | ||
} | ||
|
@@ -614,8 +618,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> { | |
} | ||
} | ||
hir::TyKind::Ref(lifetime, ..) if lifetime.is_anonymous() => { | ||
self.suggestions | ||
.push((lifetime.ident.span, make_suggestion(lifetime.ident))); | ||
self.suggestions.push((lifetime.ident.span, make_suggestion(lifetime))); | ||
} | ||
_ => {} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when does this happen to be an underscore lifetime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the
'static
is elided, e.g. for bothC
andD
here:I didn't even realize
'static
could be elided like this!I will add a comment about this.