about summary refs log tree commit diff
path: root/library/std/src/thread/local.rs
AgeCommit message (Collapse)AuthorLines
2025-08-19Tweak wording againQuinn Tucker-1/+1
2025-08-19Adjust wording for concisenessQuinn Tucker-2/+2
2025-08-19Fix typos in LocalKey documentationQuinn Tucker-2/+2
2025-07-15Add LocalKey<Cell>::updateCameron Steffen-0/+23
2025-04-18LocalKey<T>: document that the dtor should not panicLieselotte-1/+5
2025-02-21Highlight thread_local! const init in docsKornel-5/+6
2025-01-26Move std::thread_local unit tests to integration testsbjorn3-6/+0
2025-01-08Outline panicking code for `LocalKey::with`Joseph Perez-8/+16
See https://github.com/rust-lang/rust/pull/115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
2024-12-06Define acronym for thread local storageWill-Low-1/+1
There are multiple references in this module's documentation to the acronym "TLS", without defining it. This is confusing for the reader. I propose that this acronym be defined during the first use of the term.
2024-11-29Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrumbors-1/+0
Bump boostrap compiler to new beta Currently failing due to something about the const stability checks and `panic!`. I'm not sure why though since I wasn't able to see any PRs merged in the past few days that would result in a `cfg(bootstrap)` that shouldn't be removed. cc `@RalfJung` #131349
2024-11-27update cfgsBoxy-1/+0
2024-11-26Add missing code examples on `LocalKey`Guillaume Gomez-2/+28
2024-10-25Re-do recursive const stability checksRalf Jung-1/+1
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-09-29Fix std tests for wasm32-wasip2 targetNicola Krumschmidt-1/+1
2024-06-18Replace `move||` with `move ||` in `compiler/` and `library/`Vonr-1/+1
Edit from #126631 to revert changes on ui tests
2024-05-25std: make TLS accessors closures that return pointersjoboet-8/+4
2024-04-08Change method calls to using the method directlyTrevor Gross-3/+3
This is in accordance with Clippy's redundant_closure_for_method_calls.
2024-04-08Add `SAFETY` comments to the thread local implementationTrevor Gross-10/+12
Reduce `unsafe` block scope and add `SAFETY` comments.
2024-04-08Update thread local docs with idiomatic cell type useTrevor Gross-15/+17
The `thread_local!` examples use `RefCell` for `Copy` types. Update examples to have one `Copy` and one non-`Copy` type using `Cell` and `RefCell`, respectively.
2024-02-23Get rid of some `#[allow(static_mut_refs)]`Pavel Grigorenko-2/+0
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+2
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-18Improve wording of static_mut_refObei Sideg-2/+2
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-08Step all bootstrap cfgs forwardMark Rousskov-1/+1
This also takes care of other bootstrap-related changes.
2024-01-20Revert example change from PR 116392David Tolnay-4/+1
2024-01-20Allow any expression blocks in `thread_local!`Nikolai Vazquez-3/+6
2024-01-07Update test for `E0796` and `static_mut_ref` lintObei Sideg-0/+2
2024-01-02Update `thread_local` examples to use `local_key_cell_methods`Trevor Gross-18/+32
`local_key_cell_methods` has been stable for a while and provides a much less clunky way to interface with thread-local variables. Additionaly add context to the documentation about why types with interior mutability are needed.
2023-09-26std: broaden the allowed behaviour for recursive TLS initializationjoboet-3/+3
2023-08-22Replace version placeholders with 1.73.0Mark Rousskov-9/+9
2023-08-10Stabilize thread local cell methods.Mara Bos-18/+9
2023-05-15Rollup merge of #110049 - SkiFire13:localkey-with-docs-fix, r=workingjubileeMatthias Krüger-2/+2
Don't claim `LocalKey::with` prevents a reference to be sent across threads The documentation for `LocalKey` claims that `with` yields a reference that cannot be sent across threads, but this is false since you can easily do that with scoped threads. What it actually prevents is the reference from outliving the current thread.
2023-04-27Document `const {}` syntax for `std::thread_local`.Nilstrieb-2/+20
It exists and is pretty cool. More people should use it.
2023-04-26Restructure and rename thread local things in std.Mara Bos-4/+4
2023-04-07Don't claim LocalKey::with prevents a reference to be sent across threadsGiacomo Stevanato-2/+2
2023-03-10Moved thread_local implementation to sys::commonAyush Singh-373/+0
This allows removing all the platform-dependent code from `library/std/src/thread/local.rs` and `library/std/src/thread/mod.rs` Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-03-10Move __thread_local_inner to sysAyush Singh-194/+0
Move __thread_local_inner macro in crate::thread::local to crate::sys. Currently, the tidy check does not fail for `library/std/src/thread/local.rs` even though it contains platform specific code. This is beacause target_family did not exist at the time the tidy checks were written [1]. [1]: https://github.com/rust-lang/rust/pull/105861#discussion_r1125841678 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2023-01-17refactor[std]: do not use box syntaxjoboet-2/+1
2022-12-30Auto merge of #106296 - matthiaskrgr:rollup-ukdbqwx, r=matthiaskrgrbors-1/+1
Rollup of 4 pull requests Successful merges: - #99244 (doc: clearer and more correct Iterator::scan) - #103707 (Replace libstd, libcore, liballoc terminology in docs) - #104182 (`IN6ADDR_ANY_INIT` and `IN6ADDR_LOOPBACK_INIT` documentation.) - #106273 (rustdoc: remove redundant CSS `.source .content { overflow: visible }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-1/+1
2022-12-28Catch panics in destruction of TLS valuesFlorian Bartels-7/+14
`destroy_value` is/can be called from C code (libc). Unwinding from Rust to C code is undefined behavior, which is why unwinding is caught here.
2022-11-24Revert "Forbid inlining `thread_local!`'s `__getit` function on Windows"Thom Chiovoloni-16/+9
This reverts commit 3099dfdd9fc1a331eb9c53200b310fa1a06e1573.
2022-11-22Forbid inlining `thread_local!`'s `__getit` function on WindowsThom Chiovoloni-9/+16
2022-10-13sync thread_local key conditions exactly with what the macro usesRalf Jung-2/+5
2022-09-27Address feedbackmejrs-1/+1
2022-09-27Wrapper suggestionsmejrs-0/+1
2022-08-22update and extend some comments, and cfg-out some unused codeRalf Jung-0/+3
2022-05-01Fix some links in the standard libraryVadim Petrochenkov-0/+2
2022-04-17Revert "Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrum"Erik Desjardins-2/+2
This reverts commit 035a717ee8bf548868fb50b5c7ca562fc4a657a7, reversing changes made to 761e8884858759b21f3374ad610494e68c087a38.
2022-04-12Add missing unsafe marker.Mara Bos-1/+1
This is now necessary because of deny(unsafe_op_in_unsafe_fn).
2022-04-12Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).Mara Bos-0/+1
This avoids 'unused unsafe' warnings when using this feature inside std.