-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement suggestions for elided_named_lifetimes
#129840
Implement suggestions for elided_named_lifetimes
#129840
Conversation
This comment has been minimized.
This comment has been minimized.
2b60ebc
to
75bb732
Compare
Apparently this is in conflict with clippy's fn foo<'a>(x: &'a str) -> &str this suggests adding lifetime to the output, but clippy suggests removing it from the input. Applying both at the same time produces fn foo(x: &str) -> &'a str which is not correct. I would say that Though, if one applies Idk how to fix this one. cc @rust-lang/clippy |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
75bb732
to
9e2d264
Compare
It seems like without suggestions, I see three possible ways of dealing with the issue.
Footnotes |
@bors r+ rollup The easiest way to remove the conflict could be to uplift the needless_lifetimes lint to rustc. It may fit well with the current architecture of the code, but I haven't tried writing any code. |
Okay, I've managed to swap the priorities between Patchdiff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index ae7e9659856..693f1b22587 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -2639,13 +2639,6 @@ fn decorate_lint(self, diag: &mut rustc_errors::Diag<'_, G>) {
if let Some(declaration) = declaration {
diag.span_label(declaration, fluent::lint_label_named);
}
- // FIXME(GrigorenkoPV): this `if` and `return` should be removed,
- // but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
- // https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
- // HACK: `'static` suggestions will never sonflict, emit only those for now.
- if name != rustc_span::symbol::kw::StaticLifetime {
- return;
- }
match kind {
MissingLifetimeKind::Underscore => diag.span_suggestion_verbose(
span,
diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs
index ba34af9c100..793ef442c13 100644
--- a/src/tools/clippy/clippy_lints/src/lifetimes.rs
+++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs
@@ -420,6 +420,9 @@ fn could_use_elision<'tcx>(
.filter_map(|(def_id, occurrences)| {
if occurrences == 1
&& (input_lts.len() == 1 || !output_lts.iter().any(|lt| named_lifetime(lt) == Some(def_id)))
+ && !output_lts
+ .iter()
+ .any(|lt| suggested_by_elided_named_lifetimes(lt, def_id))
{
Some(def_id)
} else {
@@ -437,6 +440,10 @@ fn could_use_elision<'tcx>(
Some((elidable_lts, usages))
}
+fn suggested_by_elided_named_lifetimes(lt: &Lifetime, res: LocalDefId) -> bool {
+ lt.res == LifetimeName::Param(res) && matches!(lt.ident.name, kw::Empty | kw::UnderscoreLifetime)
+}
+
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<LocalDefId> {
named_generics
.iter() but the problem now is that
This does result in only correct code along the way, but it makes a new suggestion pop up after the previous is applied. The testsuite does not like that:
So, to reiterate my previous point:
We should probably emit The problem is that we emit I don't think we can move
It seems like uplifting is unavoidable here, because we need some information to flow from
There was an attempt to fix those but it seemingly got abandoned right at the start: rust-lang/rust-clippy#13141 rust-lang/rust-clippy#12456 Soo, should we maybe just break Footnotes
|
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#128871 (bypass linker configuration and cross target check for specific commands) - rust-lang#129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging) - rust-lang#129614 (Adjust doc comment of Condvar::wait_while) - rust-lang#129840 (Implement suggestions for `elided_named_lifetimes`) - rust-lang#129891 (Do not request sanitizers for naked functions) - rust-lang#129899 (Add Suggestions for Misspelled Keywords) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129987 (Don't store region in `CapturedPlace`) - rust-lang#130054 (Add missing quotation marks) r? `@ghost` `@rustbot` modify labels: rollup
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#128871 (bypass linker configuration and cross target check for specific commands) - rust-lang#129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging) - rust-lang#129614 (Adjust doc comment of Condvar::wait_while) - rust-lang#129840 (Implement suggestions for `elided_named_lifetimes`) - rust-lang#129891 (Do not request sanitizers for naked functions) - rust-lang#129899 (Add Suggestions for Misspelled Keywords) - rust-lang#129940 (s390x: Fix a regression related to backchain feature) - rust-lang#129987 (Don't store region in `CapturedPlace`) - rust-lang#130054 (Add missing quotation marks) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129840 - GrigorenkoPV:elided-named-lifetimes-suggestion, r=cjgillot Implement suggestions for `elided_named_lifetimes` A follow-up to rust-lang#129207, as per rust-lang#129207 (comment). r? cjgillot I will probably squash this a bit, but later. `@rustbot` label +A-lint
A follow-up to #129207, as per #129207 (comment).
r? cjgillot
I will probably squash this a bit, but later.
@rustbot label +A-lint