rust/tests/ui/traits/const-traits
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 Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
const_derives Be better at enforcing that const_conditions is only called on const items 2024-10-24 09:46:36 +00:00
effects Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
specialization Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
assoc-type-const-bound-usage-0.rs Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type-const-bound-usage-1.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
assoc-type-const-bound-usage-1.stderr Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type-const-bound-usage-fail-2.rs Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type-const-bound-usage-fail-2.stderr Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type-const-bound-usage-fail.rs Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type-const-bound-usage-fail.stderr Add support for ~const item bounds 2024-10-24 23:43:31 +00:00
assoc-type.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
assoc-type.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
attr-misuse.rs
attr-misuse.stderr
call-const-closure.rs Add tests 2024-10-24 09:46:36 +00:00
call-const-closure.stderr Add tests 2024-10-24 09:46:36 +00:00
call-const-in-tilde-const.rs Add tests 2024-10-24 09:46:36 +00:00
call-const-in-tilde-const.stderr Add tests 2024-10-24 09:46:36 +00:00
call-const-trait-method-fail.rs
call-const-trait-method-fail.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
call-const-trait-method-pass.rs
call-const-trait-method-pass.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
call-generic-in-impl.rs
call-generic-in-impl.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
call-generic-method-chain.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call-generic-method-chain.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call-generic-method-dup-bound.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call-generic-method-dup-bound.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call-generic-method-fail.rs
call-generic-method-nonconst-bound.rs
call-generic-method-nonconst.rs
call-generic-method-nonconst.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
call-generic-method-pass.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call-generic-method-pass.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
call.rs
const-and-non-const-impl.rs
const-and-non-const-impl.stderr
const-bound-in-host.rs Add tests 2024-10-24 09:46:36 +00:00
const-bound-in-host.stderr Add tests 2024-10-24 09:46:36 +00:00
const-bound-on-not-const-associated-fn.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-bound-on-not-const-associated-fn.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-bounds-non-const-trait.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-bounds-non-const-trait.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-check-fns-in-const-impl.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-check-fns-in-const-impl.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-closure-parse-not-item.rs
const-closure-parse-not-item.stderr
const-closure-trait-method-fail.rs
const-closure-trait-method-fail.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-closure-trait-method.rs
const-closure-trait-method.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-closures.rs
const-closures.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-default-method-bodies.rs
const-default-method-bodies.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop-bound.rs
const-drop-bound.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop-fail-2.precise.stderr
const-drop-fail-2.rs
const-drop-fail-2.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop-fail-2.stock.stderr
const-drop-fail.precise.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop-fail.rs
const-drop-fail.stock.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop.precise.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-drop.rs
const-drop.stock.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-fns-are-early-bound.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
const-impl-norecover.rs
const-impl-norecover.stderr
const-impl-recovery.rs
const-impl-recovery.stderr
const-impl-requires-const-trait.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-impl-requires-const-trait.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-impl-trait.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
const-in-closure.rs Add tests 2024-10-24 09:46:36 +00:00
const-in-closure.stderr Add tests 2024-10-24 09:46:36 +00:00
const-trait-bounds-trait-objects.rs
const-trait-bounds-trait-objects.stderr
const-trait-bounds.rs
const-trait-bounds.stderr
cross-crate-default-method-body-is-const.rs
cross-crate.gatednc.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
cross-crate.rs
cross-crate.stock.stderr
cross-crate.stocknc.stderr
default-method-body-is-const-body-checking.rs
default-method-body-is-const-same-trait-ck.rs
default-method-body-is-const-same-trait-ck.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
default-method-body-is-const-with-staged-api.rs
do-not-const-check-override.rs
do-not-const-check.rs
dont-observe-host-opaque.rs Add tests 2024-10-24 09:46:36 +00:00
dont-observe-host-opaque.stderr Add tests 2024-10-24 09:46:36 +00:00
dont-observe-host.rs Add tests 2024-10-24 09:46:36 +00:00
dont-observe-host.stderr Add tests 2024-10-24 09:46:36 +00:00
feature-gate.gated.stderr
feature-gate.rs
feature-gate.stock.stderr
fn-ptr-lub.rs Add tests 2024-10-24 09:46:36 +00:00
fn-ptr-lub.stderr Add tests 2024-10-24 09:46:36 +00:00
function-pointer-does-not-require-const.rs
gate.rs
gate.stderr
generic-bound.rs
generic-bound.stderr
hir-const-check.rs Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
hir-const-check.stderr Add next-solver to more effects tests 2024-10-24 09:46:36 +00:00
ice-119717-constant-lifetime.rs
ice-119717-constant-lifetime.stderr
ice-120503-async-const-method.rs
ice-120503-async-const-method.stderr
ice-121536-const-method.rs
ice-121536-const-method.stderr
ice-123664-unexpected-bound-var.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
ice-123664-unexpected-bound-var.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
ice-124857-combine-effect-const-infer-vars.rs
ice-124857-combine-effect-const-infer-vars.stderr
ice-126148-failed-to-normalize.rs
ice-126148-failed-to-normalize.stderr
impl-tilde-const-trait.rs
impl-tilde-const-trait.stderr
impl-with-default-fn-fail.rs
impl-with-default-fn-fail.stderr
impl-with-default-fn-pass.rs
inherent-impl-const-bounds.rs
inherent-impl.rs
inherent-impl.stderr
inline-incorrect-early-bound-in-ctfe.rs
inline-incorrect-early-bound-in-ctfe.stderr
issue-79450.rs Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
issue-79450.stderr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
issue-88155.rs
issue-88155.stderr
issue-92111.rs
issue-92111.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
issue-92230-wf-super-trait-env.rs
issue-100222.rs
issue-102156.rs
issue-102156.stderr
issue-102985.rs
issue-102985.stderr
issue-103677.rs
item-bound-entailment-fails.rs Add tests 2024-10-24 09:46:36 +00:00
item-bound-entailment-fails.stderr Add tests 2024-10-24 09:46:36 +00:00
item-bound-entailment.rs Add tests 2024-10-24 09:46:36 +00:00
item-bound-entailment.stderr Add tests 2024-10-24 09:46:36 +00:00
match-non-const-eq.gated.stderr
match-non-const-eq.rs
match-non-const-eq.stock.stderr
mbe-bare-trait-objects-const-trait-bounds.rs
mbe-const-trait-bound-theoretical-regression.rs
mbe-const-trait-bound-theoretical-regression.stderr
mbe-dyn-const-2015.rs
mutually-exclusive-trait-bound-modifiers.rs
mutually-exclusive-trait-bound-modifiers.stderr
nested-closure.rs
non-const-op-const-closure-non-const-outer.rs
non-const-op-const-closure-non-const-outer.stderr
non-const-op-in-closure-in-const.rs
non-const-op-in-closure-in-const.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
predicate-entailment-fails.rs Add tests 2024-10-24 09:46:36 +00:00
predicate-entailment-fails.stderr Add tests 2024-10-24 09:46:36 +00:00
predicate-entailment-passes.rs Add tests 2024-10-24 09:46:36 +00:00
predicate-entailment-passes.stderr Add tests 2024-10-24 09:46:36 +00:00
specializing-constness-2.rs
specializing-constness-2.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
specializing-constness.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
specializing-constness.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
staged-api-user-crate.rs
staged-api-user-crate.stderr
staged-api.rs Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
staged-api.stable.stderr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
staged-api.unstable.stderr Re-do recursive const stability checks 2024-10-25 20:31:40 +02:00
static-const-trait-bound.rs
std-impl-gate.gated.stderr
std-impl-gate.rs
std-impl-gate.stock.stderr
super-traits-fail-2.nn.stderr
super-traits-fail-2.ny.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-2.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-2.yn.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-2.yy.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-3.nn.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-3.ny.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-3.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail-3.yn.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits-fail.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
super-traits.rs
syntax.rs
tilde-const-and-const-params.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
tilde-const-and-const-params.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
tilde-const-assoc-fn-in-trait-impl.rs
tilde-const-in-struct-args.rs Add tests 2024-10-24 09:46:36 +00:00
tilde-const-in-struct-args.stderr Add tests 2024-10-24 09:46:36 +00:00
tilde-const-inherent-assoc-const-fn.rs
tilde-const-invalid-places.rs
tilde-const-invalid-places.stderr
tilde-const-syntax.rs
tilde-const-trait-assoc-tys.rs
tilde-twice.rs
tilde-twice.stderr
trait-default-body-stability.rs
trait-default-body-stability.stderr
trait-method-ptr-in-consts-ice.rs
trait-where-clause-const.rs Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
trait-where-clause-const.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
trait-where-clause-run.rs
trait-where-clause-self-referential.rs
trait-where-clause.rs
trait-where-clause.stderr
unsatisfied-const-trait-bound.rs
unsatisfied-const-trait-bound.stderr Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00