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

Make static lifetime of constants explicit #170

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

JoeHut
Copy link
Contributor

@JoeHut JoeHut commented Nov 17, 2023

The most recent version of clippy complains about missing explicit lifetime annotators for constants.

The most recent version of clippy complains about missing explicit
lifetime annotators for constants.
@JoeHut JoeHut requested a review from mara-schulke November 17, 2023 10:49
@mara-schulke
Copy link
Contributor

As of 1.37 there is a lint in place which encourage omitting this:

https://rust-lang.github.io/rust-clippy/stable/index.html#/redundant_static_lifetimes

Can you give me a reference when this has been changed (and in which version?)

@JoeHut
Copy link
Contributor Author

JoeHut commented Nov 17, 2023

See the discussion here: rust-lang/rust#115010
tbh, I just saw that #167 doesn't pass CI because of this and couldn't reproduce it before a rustup update.

But then again, I don't see "elided_lifetimes_in_associated_constant" in https://rust-lang.github.io/rust-clippy/stable/index.html ?!

@xfbs
Copy link
Contributor

xfbs commented Nov 20, 2023

I was quite confused by this, let me shine some light here!

As of 1.37 there is a lint in place which encourage omitting this:

https://rust-lang.github.io/rust-clippy/stable/index.html#/redundant_static_lifetimes

This is still in place — basically, when you declare a static, you do it like this (without the explicit 'static lifetime):

static MY_STATIC: &str = "important stuff here";

This has not changed.

The most recent version of clippy complains about missing explicit lifetime annotators for constants.
See the discussion here: rust-lang/rust#115010
tbh, I just saw that #167 doesn't pass CI because of this and couldn't reproduce it before a rustup update.

Yes, so crucially, this is not about lifetimes in constants, but lifetimes in associated constants. So here, we don't have a simple constant, we have a constant which is associated to a type, like this:

impl MyType {
    const MY_CONST: &'static str = "abc";
}

In this situation, we must give an explicit lifetime at the moment, according to that issue you linked.

But then again, I don't see "elided_lifetimes_in_associated_constant" in https://rust-lang.github.io/rust-clippy/stable/index.html ?!

Correct, this is not a clippy warning, but rather a compiler warning.

@xfbs xfbs self-requested a review November 20, 2023 12:05
Copy link
Contributor

@xfbs xfbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

According to rust-lang/rust#115010, we need to make these changes as they will become a hard error in the future.

@JoeHut JoeHut merged commit c832995 into helsing-ai:main Nov 20, 2023
7 checks passed
@JoeHut JoeHut deleted the jh/fix_clippy branch November 20, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants