99 Commits

Author SHA1 Message Date
Jules Bertholet 7f83c784bd Allow passing expr metavariable as a cfg predicate 2026-03-15 13:44:14 -04:00
Martin Nordholts 8e3d60447c Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
Orson Peters f9b0811d01 Add documentation guaranteeing global allocator use of TLS
Remove outdated part of comment claiming thread_local re-enters global allocator

Fix typo in doc comment

Add comments for guarantees given and footnote that System may still be called

Revise mention of using the global allocator

Allow for the possibility that the global allocator is the system allocator.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2025-11-28 00:09:12 +01:00
Jules Bertholet 4d32b9a178 Hoist non-platform-specific code out of thread_local_inner! 2025-09-27 17:05:39 -04:00
Jules Bertholet a4e87e9406 Support #[rustc_align_static] inside thread_local! 2025-09-26 13:51:09 -04:00
Ben Kimock df58fd8cf7 Change the cfg to a dash 2025-09-21 13:12:20 -04:00
Ben Kimock 888679013d Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
Quinn Tucker e84d29284c Tweak wording again 2025-08-19 19:05:19 -04:00
Quinn Tucker 14022c8a9a Adjust wording for conciseness 2025-08-19 17:14:26 -04:00
Quinn Tucker d0841c7dec Fix typos in LocalKey documentation 2025-08-19 16:47:25 -04:00
Cameron Steffen 1120cb2fe5 Add LocalKey<Cell>::update 2025-07-15 16:17:57 -05:00
Lieselotte 0d56e3eed1 LocalKey<T>: document that the dtor should not panic 2025-04-18 14:11:32 +02:00
Kornel b94162078d Highlight thread_local! const init in docs 2025-02-21 13:02:42 +00:00
bjorn3 332fb7e6f1 Move std::thread_local unit tests to integration tests 2025-01-26 10:28:05 +00:00
Joseph Perez 8ec7bae57b Outline panicking code for LocalKey::with
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.
2025-01-08 00:29:20 +01:00
Will-Low 5d8233edbf Define acronym for thread local storage
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-12-06 15:33:05 -08:00
bors 1fc691e6dd Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrum
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-29 22:39:10 +00:00
Boxy 22998f0785 update cfgs 2024-11-27 15:14:54 +00:00
Guillaume Gomez 02c3e6d087 Add missing code examples on LocalKey 2024-11-26 15:29:47 +01:00
Ralf Jung a0215d8e46 Re-do recursive const stability checks
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-10-25 20:31:40 +02:00
Nicola Krumschmidt 87f17f3ccb Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
Vonr 7321e79114 Replace move|| with move || in compiler/ and library/
Edit from #126631 to revert changes on ui tests
2024-06-18 23:25:08 +08:00
joboet 1052d2931c std: make TLS accessors closures that return pointers 2024-05-25 00:19:47 +02:00
Trevor Gross 313085f725 Change method calls to using the method directly
This is in accordance with Clippy's redundant_closure_for_method_calls.
2024-04-08 17:48:07 -04:00
Trevor Gross 6e68a2f475 Add SAFETY comments to the thread local implementation
Reduce `unsafe` block scope and add `SAFETY` comments.
2024-04-08 17:47:09 -04:00
Trevor Gross 2aec2fe3b8 Update thread local docs with idiomatic cell type use
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-04-08 17:43:24 -04:00
Pavel Grigorenko 58c8c0853f Get rid of some #[allow(static_mut_refs)] 2024-02-23 18:02:25 +03:00
Esteban Küber e5b3c7ef14 Add rustc_confusables annotations to some stdlib APIs
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-22 18:04:55 +00:00
Obei Sideg 408eeae59d Improve wording of static_mut_ref
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-18 06:01:40 +03:00
Mark Rousskov 9a5034a20e Step all bootstrap cfgs forward
This also takes care of other bootstrap-related changes.
2024-02-08 07:44:34 -05:00
David Tolnay f52b88e91f Revert example change from PR 116392 2024-01-20 18:39:48 -08:00
Nikolai Vazquez fc75a4e146 Allow any expression blocks in thread_local! 2024-01-20 18:39:16 -08:00
Obei Sideg a8aa6878f6 Update test for E0796 and static_mut_ref lint 2024-01-07 17:29:25 +03:00
Trevor Gross 6f49080fa8 Update thread_local examples to use local_key_cell_methods
`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.
2024-01-02 22:24:26 -06:00
joboet 559ec69e41 std: broaden the allowed behaviour for recursive TLS initialization 2023-09-26 12:54:01 +02:00
Mark Rousskov c8522adb97 Replace version placeholders with 1.73.0 2023-08-22 06:57:00 -04:00
Mara Bos dc3cbc1e56 Stabilize thread local cell methods. 2023-08-10 17:33:40 +02:00
Matthias Krüger c93c2985d8 Rollup merge of #110049 - SkiFire13:localkey-with-docs-fix, r=workingjubilee
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-05-15 17:12:44 +02:00
Nilstrieb b56d85dc09 Document const {} syntax for std::thread_local.
It exists and is pretty cool. More people should use it.
2023-04-27 20:24:18 +02:00
Mara Bos fba5cfe482 Restructure and rename thread local things in std. 2023-04-26 21:02:29 +02:00
Giacomo Stevanato 2563fbeab3 Don't claim LocalKey::with prevents a reference to be sent across threads 2023-04-07 14:57:50 +02:00
Ayush Singh 5828910ff4 Moved thread_local implementation to sys::common
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-10 23:25:32 +05:30
Ayush Singh ffa9019134 Move __thread_local_inner to sys
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-03-10 17:35:24 +05:30
joboet 7f2cf19191 refactor[std]: do not use box syntax 2023-01-17 14:08:35 +01:00
bors bbdca4c28f Auto merge of #106296 - matthiaskrgr:rollup-ukdbqwx, r=matthiaskrgr
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-30 16:10:00 +00:00
jonathanCogan db47071df2 Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
Florian Bartels 04a6f22f79 Catch panics in destruction of TLS values
`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-12-28 18:32:41 +01:00
Thom Chiovoloni 24712f9982 Revert "Forbid inlining thread_local!'s __getit function on Windows"
This reverts commit 3099dfdd9f.
2022-11-24 18:12:12 -08:00
Thom Chiovoloni 3099dfdd9f Forbid inlining thread_local!'s __getit function on Windows 2022-11-22 02:09:47 -08:00
Ralf Jung 600ac6959a sync thread_local key conditions exactly with what the macro uses 2022-10-13 14:09:08 +02:00