rust-lang / rust-lang/rust-clippy

Lint request: Prevent lifetimes that are only used for function output

Open
#1,874 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint good first issue L-correctness S-needs-discussion T-middle
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

The following:

fn lifetime<'a>() -> &'a str {
    "Why some people do that"
}

Can be more clearly written as this. Also, using 'static lifetime makes it clear that it was intended, especially in unsafe code where returning unbound lifetime may as well be a mistake.

fn lifetime() -> &'static str {
    "Why some people do that"
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides Rust examples but names no files, tests, or entry points. Start by locating Clippy's lint infrastructure and related lifetime lints, then define the cases the lint should report and add coverage showing that the proposed examples produce the intended diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.