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
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: