-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Move elided_named_lifetimes
into a separate pass
#130150
base: master
Are you sure you want to change the base?
Move elided_named_lifetimes
into a separate pass
#130150
Conversation
This comment has been minimized.
This comment has been minimized.
9174d9f
to
be8f80a
Compare
This comment has been minimized.
This comment has been minimized.
be8f80a
to
4d638bd
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
I'm not sure if it is possible to fix those false negatives at all with this approach |
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #107251) made this pull request unmergeable. Please resolve the merge conflicts. |
fn check_trait_item(&mut self, _: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) { | ||
if let TraitItemKind::Const(..) = item.kind { | ||
self.allow_static = true; | ||
} | ||
} | ||
fn check_trait_item_post(&mut self, _: &LateContext<'tcx>, _: &'tcx TraitItem<'tcx>) { | ||
self.allow_static = false; | ||
} | ||
|
||
fn check_impl_item(&mut self, _: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>) { | ||
if let ImplItemKind::Const(..) = item.kind { | ||
self.allow_static = true; | ||
} | ||
} | ||
fn check_impl_item_post(&mut self, _: &LateContext<'tcx>, _: &'tcx ImplItem<'tcx>) { | ||
self.allow_static = false; | ||
} | ||
|
||
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { | ||
if let ItemKind::Const(..) | ItemKind::Static(..) = item.kind { | ||
self.allow_static = true; | ||
} | ||
} | ||
fn check_item_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Item<'tcx>) { | ||
self.allow_static = false; | ||
} |
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.
I'm not convinced this handles cases like:
const FOO: ConstGeneric<{
const BAR: usize = 5;
BAR
}, &u8> = /* */;
You may need an actual stack.
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.
I think just storing the id of the outermost item would be enough.
However, I am reluctant to move any further with this PR as I suspect some lifetimes, which are present in AST, are not present in HIR and thus are unlintable with this approach.
@GrigorenkoPV |
I am reluctant to move forward with it, since some lifetimes (which appear in AST, where this lint would previously run) seem to be not preserved after the translation to HIR, where the lint would run after this PR. You can see those changes in the tests' diff. IMO, the places where the lifetimes disappear are one of the most valuable ones as they involve pretty complex signatures with The main reason for this PR was to move In any case, |
r? @cjgillot
Trying to move forward with #129840 (comment)
Current results, from sad to happy:
ElidedNamedLifetime
diagnostic decorator can almost be moved from a hand-rolled impl to a derived one. (Is that a good thing?) The only problem seems to be that you can't slap both#[label]
&#[primary_span]
on the same field.ElidedNamedLifetimes
pass. Yay.LateLintPass
now hascheck_trait_item_post
&check_lifetime
.MissingLifetime.id_for_lint
& theLifetimeRes::Static.suppress_elision_warning
hacks got removed.