rust/library/std/src
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
..
backtrace remove redundant imports 2023-12-10 10:56:22 +08:00
collections replace placeholder version 2024-10-15 20:13:55 -07:00
env Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
error Reformat use declarations. 2024-07-29 08:26:52 +10:00
f16 std float tests: special-case Miri in feature detection 2024-08-08 12:17:50 +02:00
f32 these tests seem to work fine on i586 these days 2024-09-10 15:57:40 -07:00
f64 these tests seem to work fine on i586 these days 2024-09-10 15:57:40 -07:00
f128 Add core functions for f16 and f128 that require math routines 2024-08-01 15:38:53 -04:00
ffi Use &raw in the standard library 2024-09-25 17:03:20 -07:00
fs Use &raw in the standard library 2024-09-25 17:03:20 -07:00
hash std: implement the random feature 2024-09-23 10:29:51 +02:00
io Specialize read_exact and read_buf_exact for VecDeque 2024-10-23 10:09:24 +02:00
net Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton 2024-09-30 19:18:49 -04:00
num removed nonfunctioning benchmark 2024-01-11 11:30:12 -05:00
os Rollup merge of #131654 - betrusted-io:xous-various-fixes, r=thomcc 2024-10-18 06:59:05 +02:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
pipe Cleanup sys module to match house style 2024-07-30 19:22:54 +00:00
prelude Avoid comments that describe multiple use items. 2024-07-17 08:02:46 +10:00
process [musl] use posix_spawn if a directory change was requested 2024-10-23 22:11:55 -07:00
sync mpmc doctest: make sure main thread waits for child threads 2024-10-02 08:00:17 +02:00
sys Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
sys_common std: replace LazyBox with OnceBox 2024-10-01 22:05:35 +02:00
thread Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
time Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
alloc.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
ascii.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
backtrace.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
env.rs Rollup merge of #128535 - mmvanheusden:master, r=workingjubilee 2024-09-17 17:28:31 +02:00
error.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
f16.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f32.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f64.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
f128.rs Make some float methods unstable const fn 2024-10-15 10:46:33 +02:00
fs.rs fix docs 2024-10-20 18:25:38 +03:00
keyword_docs.rs Update use keyword docs to describe precise capturing 2024-10-18 21:17:08 +00:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs Auto merge of #123550 - GnomedDev:remove-initial-arc, r=Noratrieb 2024-10-24 13:35:50 +00:00
macros.rs Add math functions for f16 and f128 2024-08-01 15:38:51 -04:00
num.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
panic.rs Auto merge of #128321 - BatmanAoD:catch-unwind-doc-update, r=Mark-Simulacrum 2024-09-29 05:54:47 +00:00
panicking.rs Rollup merge of #130846 - ChrisDenton:revert-break, r=Noratrieb 2024-09-26 22:20:54 -07:00
pat.rs Add pattern types to parser 2024-04-08 11:57:17 +00:00
path.rs Use &raw in the standard library 2024-09-25 17:03:20 -07:00
pipe.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
process.rs Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
random.rs AIX use /dev/urandom for impl 2024-10-22 20:18:11 -04:00
rt.rs Remove the Arc rt::init allocation for thread info 2024-10-19 14:39:20 +01:00
time.rs [Clippy] Swap instant_subtraction to use diagnostic item instead of path 2024-09-19 13:13:42 +01:00