Skip to content
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

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

Closed
kennytm opened this issue Oct 14, 2018 · 1 comment · Fixed by #96833
Assignees
Labels
A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Oct 14, 2018

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

@kennytm kennytm added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 14, 2018
@jhpratt
Copy link
Member

jhpratt commented Nov 14, 2019

enums are also linted here as of 1.40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants