Skip to content

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

Closed as not planned

Description

@jieyouxu

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)

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 5, 2025
  2. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 5, 2025
  3. shepmaster commented on Jul 16, 2025

    @shepmaster
    Member

    We've drastically reworded the lint in #143914, so I'm going to mark this issue as overcome-by-events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.L-mismatched_lifetime_syntaxesLint: mismatched_lifetime_syntaxesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions