rust/tests/ui/stability-attribute
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
..
auxiliary
accidental-stable-in-unstable.rs
accidental-stable-in-unstable.stderr Bless tests 2024-01-13 12:46:58 -05:00
allow-unstable-reexport.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
allow-unstable-reexport.stderr Bless tests 2024-01-13 12:46:58 -05:00
allowed-through-unstable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
allowed-through-unstable.stderr Bless tests 2024-01-13 12:46:58 -05:00
const-stability-attribute-implies-missing.rs Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
const-stability-attribute-implies-missing.stderr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
const-stability-attribute-implies-no-feature.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
const-stability-attribute-implies-no-feature.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
const-stability-attribute-implies-using-stable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
const-stability-attribute-implies-using-stable.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
const-stability-attribute-implies-using-unstable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
const-stability-attribute-implies-using-unstable.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
ctor-stability.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
default-body-stability-err.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
default-body-stability-err.stderr Bless tests 2024-01-13 12:46:58 -05:00
default-body-stability-ok-enables.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
default-body-stability-ok-impls.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generics-default-stability-trait.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generics-default-stability-trait.stderr Bless tests 2024-01-13 12:46:58 -05:00
generics-default-stability-where.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generics-default-stability-where.stderr Bless tests 2024-01-13 12:46:58 -05:00
generics-default-stability.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
generics-default-stability.stderr Bless tests 2024-01-13 12:46:58 -05:00
issue-28075.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-28075.stderr Bless tests 2024-01-13 12:46:58 -05:00
issue-28388-3.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-28388-3.stderr Bless tests 2024-01-13 12:46:58 -05:00
issue-99286-stable-intrinsics.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-106589.rs
issue-106589.stderr ast: Standardize visiting order for attributes and node IDs 2024-06-24 16:08:51 +03:00
issue-109177.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-109177.stderr
missing-const-stability.rs Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
missing-const-stability.stderr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
missing-stability-attr-at-top-level.rs
missing-stability-attr-at-top-level.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
stability-attribute-implies-missing.rs
stability-attribute-implies-missing.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
stability-attribute-implies-no-feature.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-implies-no-feature.stderr Bless tests 2024-01-13 12:46:58 -05:00
stability-attribute-implies-using-stable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-implies-using-stable.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
stability-attribute-implies-using-unstable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-implies-using-unstable.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
stability-attribute-issue-43027.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-issue.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-issue.stderr Bless tests 2024-01-13 12:46:58 -05:00
stability-attribute-non-staged-force-unstable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stability-attribute-non-staged-force-unstable.stderr
stability-attribute-non-staged.rs
stability-attribute-non-staged.stderr
stability-attribute-sanity-2.rs
stability-attribute-sanity-2.stderr
stability-attribute-sanity-3.rs
stability-attribute-sanity-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
stability-attribute-sanity-4.rs Preserve deprecation attribute even if 'since' version is missing 2023-10-30 15:48:46 -07:00
stability-attribute-sanity-4.stderr Preserve deprecation attribute even if 'since' version is missing 2023-10-30 15:48:46 -07:00
stability-attribute-sanity.rs Store version of deprecated attribute in structured form 2023-10-29 22:42:32 -07:00
stability-attribute-sanity.stderr Store version of deprecated attribute in structured form 2023-10-29 22:42:32 -07:00
stability-attribute-trait-impl.rs Update since stability attributes in tests 2023-10-23 13:04:47 -07:00
stability-attribute-trait-impl.stderr Update since stability attributes in tests 2023-10-23 13:04:47 -07:00
stability-in-private-module.rs refer to a different module in UI test 2024-03-31 15:38:22 +02:00
stability-in-private-module.stderr refer to a different module in UI test 2024-03-31 15:38:22 +02:00
stable-in-unstable.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
stable-in-unstable.stderr Bless tests 2024-01-13 12:46:58 -05:00
suggest-vec-allocator-api.rs
suggest-vec-allocator-api.stderr Bless tests 2024-01-13 12:46:58 -05:00
unresolved_stability_lint.rs
unresolved_stability_lint.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00