Skip to content

False positive: const_static_lifetime #2438

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

Closed
myrrlyn opened this issue Feb 5, 2018 · 1 comment
Closed

False positive: const_static_lifetime #2438

myrrlyn opened this issue Feb 5, 2018 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy

Comments

@myrrlyn
Copy link

myrrlyn commented Feb 5, 2018

$ rustc --version
rustc 1.25.0-nightly (0c6091fbd 2018-02-04)
$ cargo clippy --version
0.0.186

Running cargo clippy over my project with #![cfg_attr(feature = "cargo-clippy", deny(clippy))] set results in the following errors:

error: Constants have by default a `'static` lifetime

    const KEYWORD: &'static str = "whatever";
                   -^^^^^^^----- help: consider removing `'static`: `&str`

Doing so promptly results in

error[E0106]: missing lifetime specifier

    const KEYWORD: &str = "whatever";
                   ^ expected lifetime parameter

I presume that following Clippy's advice and running into a compiler-enforced hard error is a bug in Clippy?

In this particular case, the const in question is a trait associated constant:

trait Keyword {
    const KEYWORD: &'static str;
}

and the positions it is reporting for change are implementations of it:

impl Keyword for Whatever {
    const KEYWORD: &'static str = "whatever";
}

Removing any 'static marker, whether in the trait declaration or in implementations of it, causes E0106 to occur.

@oli-obk oli-obk added C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy labels Feb 6, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Feb 6, 2018

We just need to skip impl and trait items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

2 participants