rust/tests/ui/const-generics/issues
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 Remove some unnecessary allow(incomplete_features) 2024-03-11 19:42:04 +00:00
issue-56445-1.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-56445-1.min.stderr Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-56445-1.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-56445-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-56445-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-56445-3.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-56445-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-60818-struct-constructors.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-61336-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-61336-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-61336-2.stderr Remove extra # from url 2024-01-24 00:41:45 +01:00
issue-61336.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-61336.stderr Remove extra # from url 2024-01-24 00:41:45 +01:00
issue-61422.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-61432.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-62187-encountered-polymorphic-const.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-62878.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-62878.min.stderr Automatically taint when reporting errors from ItemCtxt 2024-07-09 07:44:17 +00:00
issue-62878.rs Automatically taint when reporting errors from ItemCtxt 2024-07-09 07:44:17 +00:00
issue-63322-forbid-dyn.full.stderr Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-63322-forbid-dyn.min.stderr Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-63322-forbid-dyn.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-64519.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-66596-impl-trait-for-str-const-arg.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-66906.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67185-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67185-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-67185-2.stderr Use TraitRef::to_string sorting in favor of TraitRef::ord, as the latter compares DefIds which we need to avoid 2024-03-27 14:02:15 +00:00
issue-67375.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67375.min.stderr Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
issue-67375.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67739.full.stderr Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-67739.min.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67739.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67945-1.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67945-1.min.stderr Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
issue-67945-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67945-2.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67945-2.min.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67945-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67945-3.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67945-3.min.stderr Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
issue-67945-3.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-67945-4.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67945-4.min.stderr Improve the diagnostics for unused generic parameters 2024-02-01 16:18:03 +01:00
issue-67945-4.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-68104-print-stack-overflow.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-68366.full.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-68366.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-68366.rs Merge check_mod_impl_wf and check_mod_type_wf 2024-03-07 06:27:09 +00:00
issue-68596.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-68615-adt.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-68615-adt.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-68615-array.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-68615-array.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-69654-run-pass.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-69654-run-pass.stderr Update tests 2024-02-07 10:42:01 +08:00
issue-70125-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70125-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70167.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70180-1-stalled_on.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70180-2-stalled_on.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70225.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-70273-assoc-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-71169.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-71169.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-71169.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-71202.rs Check that return type is WF in typeck 2024-03-06 16:51:17 +05:30
issue-71202.stderr Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-71381.full.stderr Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
issue-71381.min.stderr Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
issue-71381.rs Avoid follow-up errors and ICEs after missing lifetime errors on data structures 2024-07-11 11:00:15 +00:00
issue-71382.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-71382.min.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-71382.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-71547.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-71611.full.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-71611.min.stderr Allow type_of to return partially non-error types if the type was already tainted 2024-05-28 11:55:20 +00:00
issue-71611.rs Allow type_of to return partially non-error types if the type was already tainted 2024-05-28 11:55:20 +00:00
issue-71986.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-72352.full.stderr Use the correct char type on all platforms 2024-02-14 11:12:19 +00:00
issue-72352.min.stderr Use the correct char type on all platforms 2024-02-14 11:12:19 +00:00
issue-72352.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-72845.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-72845.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73120.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-73260.rs Remove save-analysis. 2023-02-16 15:14:45 +11:00
issue-73260.stderr Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
issue-73491.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-73491.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-73727-static-reference-array-const-param.min.stderr Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-73727-static-reference-array-const-param.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-74101.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-74101.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-74255.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-74255.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-74906.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-74950.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-74950.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-75047.min.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-75047.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-75299.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-76701-ty-param-in-const.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-76701-ty-param-in-const.stderr generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
issue-79674.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-79674.stderr Deduplicate more sized errors on call exprs 2024-01-24 02:53:15 +00:00
issue-80062.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-80062.stderr generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
issue-80375.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-80375.stderr generic_const_exprs: suggest to add the feature, not use it 2023-11-30 20:59:51 +01:00
issue-82956.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-82956.stderr Tweak output of import suggestions 2024-06-13 20:22:21 +00:00
issue-83249.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-83249.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-83288.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-83466.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-83466.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-83765.rs Reorder check_item_type diagnostics so they occur next to the corresponding check_well_formed diagnostics 2024-01-02 14:17:56 +00:00
issue-83765.stderr Reorder check_item_type diagnostics so they occur next to the corresponding check_well_formed diagnostics 2024-01-02 14:17:56 +00:00
issue-84659.fixed Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-84659.rs Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-84659.stderr Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-85031-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-85031-2.stderr Fix known-bug, silence ICE stderr 2023-01-19 20:20:58 +00:00
issue-86033.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-86530.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-86530.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-86535-2.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-86535.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-86820.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-86820.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-87076.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-87470.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-87493.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
issue-87493.stderr diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
issue-87964.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-88119.rs Migrate tests to use -Znext-solver 2024-06-30 17:08:45 +00:00
issue-88119.stderr Add ConstArgKind::Path and make ConstArg its own HIR node 2024-07-16 19:27:28 -07:00
issue-88468.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-88997.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-88997.stderr improve diagnostics and bless tests 2023-05-05 21:42:54 +01:00
issue-89146.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-89304.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-89320.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-89334.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-90318.rs Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
issue-90318.stderr Provide structured suggestion for #![feature(foo)] 2024-03-18 16:08:58 +00:00
issue-90364.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-90364.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-90455.fixed Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-90455.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-90455.stderr Provide structured suggestion for unconstrained generic constant 2024-03-21 00:03:59 +00:00
issue-92186.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-96654.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-97278.rs Implement custom diagnostic for ConstParamTy 2023-06-01 18:21:42 +00:00
issue-97278.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-97634.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-98629.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-98629.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-99641.rs Implement custom diagnostic for ConstParamTy 2023-06-01 18:21:42 +00:00
issue-99641.stderr Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-100313.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00
issue-100313.stderr Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
issue-105037.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-105821.rs Split part of adt_const_params into unsized_const_params 2024-07-17 11:01:29 +01:00