Skip to content

single_use_lifetime should not be emitted for traits with a lifetime parameter and a single function using it #55057

Closed
@kennytm

Description

@kennytm

Repro (on 1.27-stable to 1.31-nightly):

#![warn(single_use_lifetimes)]

pub trait Tfv<'a>: Sized {
    fn tfv(x: &'a str) -> Option<Self>;
    // fn shut_up_single_use_lifetimes(_: &'a ()) {} // uncomment to shut up the lint 😕 
}

Unexpected lint result:

warning: lifetime parameter `'a` only used once
 --> src/lib.rs:3:15
  |
3 | pub trait Tfv<'a>: Sized {
  |               ^^ this lifetime...
4 |     fn tfv(x: &'a str) -> Option<Self>;
  |                -- ...is used only here
  |

cc #44752

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-lint-single_use_lifetimes`single_use_lifetimes` lintT-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