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 false positive: panicking Cell and RefCell initialization #12637
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
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Comments
dtolnay
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
Apr 5, 2024
rustbot
added
the
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
label
Apr 5, 2024
m-rph
added
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
I-false-positive
Issue: The lint was triggered on code it shouldn't have
and removed
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
I-false-positive
Issue: The lint was triggered on code it shouldn't have
labels
Apr 17, 2024
m-rph
added a commit
to m-rph/rust-clippy
that referenced
this issue
Apr 17, 2024
…hable initializers This commit introduces a check to ensure that the lint won't trigger when the initializer is unreachable, such as: ``` thread_local! { static STATE: Cell<usize> = panic!(); } ``` This is achieved by looking at the unpeeled initializer expression and ensuring that the parent macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`. fixes rust-lang#12637 changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
m-rph
pushed a commit
to m-rph/rust-clippy
that referenced
this issue
Apr 17, 2024
…hable initializers This commit introduces a check to ensure that the lint won't trigger when the initializer is unreachable, such as: ``` thread_local! { static STATE: Cell<usize> = panic!(); } ``` This is achieved by looking at the unpeeled initializer expression and ensuring that the parent macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`. fixes rust-lang#12637 changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
blyxyas
pushed a commit
to m-rph/rust-clippy
that referenced
this issue
Apr 19, 2024
…hable initializers This commit introduces a check to ensure that the lint won't trigger when the initializer is unreachable, such as: ``` thread_local! { static STATE: Cell<usize> = panic!(); } ``` This is achieved by looking at the unpeeled initializer expression and ensuring that the parent macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`. fixes rust-lang#12637 changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
bors
added a commit
that referenced
this issue
Apr 19, 2024
Threadlocal_initializer_can_be_made_const will not trigger for unreachable initializers This commit introduces a check to ensure that the lint won't trigger when the initializer is unreachable, such as: ``` thread_local! { static STATE: Cell<usize> = panic!(); } ``` This is achieved by looking at the unpeeled initializer expression and ensuring that the parent macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`. fixes #12637 changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
bors
added a commit
that referenced
this issue
Apr 20, 2024
Threadlocal_initializer_can_be_made_const will not trigger for unreachable initializers This commit introduces a check to ensure that the lint won't trigger when the initializer is unreachable, such as: ``` thread_local! { static STATE: Cell<usize> = panic!(); } ``` This is achieved by looking at the unpeeled initializer expression and ensuring that the parent macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`. fixes #12637 changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
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
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
The
set
methods onLocalKey<Cell<T>>
andLocalKey<RefCell<T>>
are guaranteed to bypass the thread_local's initialization expression. See rust-lang/rust#92122. Thus,= panic!()
is a useful idiom for forcing the use ofset
on each thread before it accesses the thread local in any other manner.Clippy suggests replacing this with
= const { panic!() }
, which does not compile.Lint Name
thread_local_initializer_can_be_made_const
Reproducer
The suggested change makes the code not compile.
Version
Additional Labels
@rustbot label +I-suggestion-causes-error
The text was updated successfully, but these errors were encountered: