Skip to content

False positive: const_static_lifetime #2438

@myrrlyn

Description

@myrrlyn
$ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thinggood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions