Skip to content

Suggestion follow-up for mismatched-lifetime-syntaxes lint #142087

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

Open
jieyouxu opened this issue Jun 5, 2025 · 0 comments
Open

Suggestion follow-up for mismatched-lifetime-syntaxes lint #142087

jieyouxu opened this issue Jun 5, 2025 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. L-mismatched_lifetime_syntaxes Lint: mismatched_lifetime_syntaxes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Jun 5, 2025

Not a blocker, but just for our consideration (now or in the future), this ordering is going to suggest changing

fn f<'a>(_: &'a ()) -> &() { loop {} }

to this

fn f<'a>(_: &'a ()) -> &'a () { loop {} }

which then clippy is going to immediately lint on in favor of this:

fn f(_: &()) -> &() { loop {} }

In that case, it does seem like it would be better for rustc to suggest eliding the lifetime. Of course, the harder case looks like this:

fn f<'a>(&'a self, _: &()) -> &() { loop {} }

There, maybe we could still justify making the elision to

fn f(&self, _: &()) -> &() { loop {} }

since that is, after all, the language choice we made about how these elisions should work for methods, and probably if I were to annotate a lifetime here, I'd annotate the other one, but I could see the case for not removing the name here.

Originally posted by @traviscross in #138677 (comment)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 5, 2025
@jieyouxu jieyouxu added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` L-mismatched_lifetime_syntaxes Lint: mismatched_lifetime_syntaxes and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. L-mismatched_lifetime_syntaxes Lint: mismatched_lifetime_syntaxes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants