rust/tests/ui/statics
bors 9629b90b3f Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, r=compiler-errors
Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params`

Fixes #112219
Fixes #112124
Fixes #112125

### Motivation

Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of.

Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics.

This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics.

Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`.

### Implementation

The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound.

There are a few constraints here:
- We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`.
- Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]`

Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter.

Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`.

Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`.

Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
2024-07-21 05:36:21 +00:00
..
auxiliary Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
check-immutable-mut-slices.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
check-immutable-mut-slices.stderr Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
check-recursion-foreign.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
check-values-constraints.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
check-values-constraints.stderr Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
const_generics.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-14227.rs Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
issue-14227.stderr Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
issue-15261.rs Improve wording of static_mut_ref 2024-02-18 06:01:40 +03:00
issue-15261.stderr Use more accurate span for addr_of! suggestion 2024-07-18 18:39:20 +00:00
issue-17233.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-17718-static-sync.rs
issue-17718-static-sync.stderr
issue-17718-static-unsafe-interior.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-44373-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-44373.rs
issue-44373.stderr
issue-91050-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-91050-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
missing_lifetime.rs Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
missing_lifetime.stderr Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
mutable_memory_validation.rs Always use a colon in //@ normalize-*: headers 2024-07-11 12:23:44 +10:00
mutable_memory_validation.stderr Validate nested static items 2024-04-17 09:50:15 +00:00
nested_struct.rs [Refactor] Rename Lint and LintGroup\'s is_loaded to is_externally_loaded 2024-04-29 15:57:09 +02:00
nested_thread_local.rs Forbid implicit nested statics in thread local statics 2024-04-02 13:00:46 +00:00
nested_thread_local.stderr Forbid implicit nested statics in thread local statics 2024-04-02 13:00:46 +00:00
nested-allocations-dont-inherit-codegen-attrs.rs Don't inherit codegen attrs from parent static 2024-03-31 22:34:00 -04:00
recursive_interior_mut.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-fn-inline-xc.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-fn-trait-xc.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-function-pointer-xc.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-function-pointer.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-impl.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-impl.stderr
static-method-in-trait-with-tps-intracrate.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-method-xcrate.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-methods-in-traits2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-methods-in-traits.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-mut-xc.rs Improve wording of static_mut_ref 2024-02-18 06:01:40 +03:00
static-mut-xc.stderr Use more accurate span for addr_of! suggestion 2024-07-18 18:39:20 +00:00
static-promotion.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
static-recursive.rs Improve wording of static_mut_ref 2024-02-18 06:01:40 +03:00
static-recursive.stderr Use more accurate span for addr_of! suggestion 2024-07-18 18:39:20 +00:00
uninhabited-static.rs Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
uninhabited-static.stderr Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
unsized_type2.rs Taint const qualifs if a static is referenced that didn't pass wfcheck 2024-04-16 10:43:41 +00:00
unsized_type2.stderr Taint const qualifs if a static is referenced that didn't pass wfcheck 2024-04-16 10:43:41 +00:00