Skip to content

Single use lifetimes lint suggests using unstable feature on stable #135550

Open
@jaskij

Description

@jaskij

Code

playground link

#[allow(dead_code)]
#[warn(single_use_lifetimes)]
fn foo<'a>(_items: impl IntoIterator<Item = &'a i64>) -> Vec<f64> {
    vec![]
}

Current output

warning: lifetime parameter `'a` only used once
 --> src/lib.rs:3:8
  |
3 | fn foo<'a>(_items: impl IntoIterator<Item = &'a i64>) -> Vec<f64> {
  |        ^^ this lifetime...                   -- ...is used only here
  |
note: the lint level is defined here
 --> src/lib.rs:2:8
  |
2 | #[warn(single_use_lifetimes)]
  |        ^^^^^^^^^^^^^^^^^^^^
help: elide the single-use lifetime
  |
3 - fn foo<'a>(_items: impl IntoIterator<Item = &'a i64>) -> Vec<f64> {
3 + fn foo(_items: impl IntoIterator<Item = &i64>) -> Vec<f64> {

Desired output

No warning

Rationale and extra context

The feature required to elide the single use lifetime is unstable

Rust Version

$ rustc --version --verbose
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5

and

$ rustc --version --verbose
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-false-positiveLint: False positive (should not have fired).T-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