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

thread_local_initializer_can_be_made_const should respect MSRV #12404

Closed
taiki-e opened this issue Mar 3, 2024 · 0 comments · Fixed by #12405
Closed

thread_local_initializer_can_be_made_const should respect MSRV #12404

taiki-e opened this issue Mar 3, 2024 · 0 comments · Fixed by #12405
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@taiki-e
Copy link
Member

taiki-e commented Mar 3, 2024

Summary

thread_local_const_init has been stabilized in 1.59 (rust-lang/rust#91355), but this lint is also triggered for code with MSRV less than 1.59.

Mentioning @partiallytyped, who implemented this lint in #12026.

Lint Name

thread_local_initializer_can_be_made_const

Reproducer

I tried this code:

#![warn(clippy::thread_local_initializer_can_be_made_const)]
#![allow(dead_code)]

#[clippy::msrv = "1.58"]
fn f() {
    thread_local! {
        static TLS: i32 = 1;
    }
}

I saw this happen:

warning: initializer for `thread_local` value can be made `const`
 --> src/lib.rs:7:27
  |
7 |         static TLS: i32 = 1;
  |                           ^ help: replace with: `const { 1 }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#thread_local_initializer_can_be_made_const
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::thread_local_initializer_can_be_made_const)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen: no warning

playground

Version

rustc 1.78.0-nightly (5119208fd 2024-03-02)
binary: rustc
commit-hash: 5119208fd78a77547c705d1695428c88d6791263
commit-date: 2024-03-02
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0

Additional Labels

No response

@taiki-e taiki-e added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 3, 2024
bors added a commit that referenced this issue Mar 3, 2024
Added msrv to threadlocal initializer check

closes: #12404
@bors bors closed this as completed in aceeb54 Mar 3, 2024
taiki-e pushed a commit to rust-lang/futures-rs that referenced this issue Sep 14, 2024
* Fix unexpected `cfg` condition name: ... warnings introduced in Rust 1.80

See https://blog.rust-lang.org/2024/05/06/check-cfg.html

* io_slice_advance feature is now stable

* clippy: enable missing_const_for_thread_local lint, now checks for MSRV (see rust-lang/rust-clippy#12404)

* clippy: fixes for "doc list item without indentation" lint

* clippy: ignore incorrect "first doc comment paragraph is too long" warning

see rust-lang/rust-clippy#13315

* clippy: allow long first paragraphs in select... fn doc comments

* use workspace level setting to ignore error about the futures_sanitizer unexpected config
taiki-e pushed a commit to rust-lang/futures-rs that referenced this issue Oct 5, 2024
* Fix unexpected `cfg` condition name: ... warnings introduced in Rust 1.80

See https://blog.rust-lang.org/2024/05/06/check-cfg.html

* io_slice_advance feature is now stable

* clippy: enable missing_const_for_thread_local lint, now checks for MSRV (see rust-lang/rust-clippy#12404)

* clippy: fixes for "doc list item without indentation" lint

* clippy: ignore incorrect "first doc comment paragraph is too long" warning

see rust-lang/rust-clippy#13315

* clippy: allow long first paragraphs in select... fn doc comments

* use workspace level setting to ignore error about the futures_sanitizer unexpected config
taiki-e pushed a commit to rust-lang/futures-rs that referenced this issue Oct 5, 2024
* Fix unexpected `cfg` condition name: ... warnings introduced in Rust 1.80

See https://blog.rust-lang.org/2024/05/06/check-cfg.html

* io_slice_advance feature is now stable

* clippy: enable missing_const_for_thread_local lint, now checks for MSRV (see rust-lang/rust-clippy#12404)

* clippy: fixes for "doc list item without indentation" lint

* clippy: ignore incorrect "first doc comment paragraph is too long" warning

see rust-lang/rust-clippy#13315

* clippy: allow long first paragraphs in select... fn doc comments

* use workspace level setting to ignore error about the futures_sanitizer unexpected config
taiki-e pushed a commit to rust-lang/futures-rs that referenced this issue Oct 5, 2024
* Fix unexpected `cfg` condition name: ... warnings introduced in Rust 1.80

See https://blog.rust-lang.org/2024/05/06/check-cfg.html

* io_slice_advance feature is now stable

* clippy: enable missing_const_for_thread_local lint, now checks for MSRV (see rust-lang/rust-clippy#12404)

* clippy: fixes for "doc list item without indentation" lint

* clippy: ignore incorrect "first doc comment paragraph is too long" warning

see rust-lang/rust-clippy#13315

* clippy: allow long first paragraphs in select... fn doc comments

* use workspace level setting to ignore error about the futures_sanitizer unexpected config
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 I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant