rust/tests/ui/const-generics
bors af06dce64b Auto merge of #106281 - JulianKnodt:transmute_const_generics, r=b-naber
Add ability to transmute (somewhat) with generic consts in arrays

Previously if the expression contained generic consts and did not have a directly equivalent type, transmuting the type in this way was forbidden, despite the two sizes being identical. Instead, we should be able to lazily tell if the two consts are identical, and if so allow them to be transmuted.

This is done by normalizing the forms of expressions into sorted order of multiplied terms, which is not generic over all expressions, but should handle most cases.

This allows for some _basic_ transmutations between types that are equivalent in size without requiring additional stack space at runtime.

I only see one other location at which `SizeSkeleton` is being used, and it checks for equality so this shouldn't affect anywhere else that I can tell.

See [this Stackoverflow post](https://stackoverflow.com/questions/73085012/transmute-nested-const-generic-array-rust) for what was previously necessary to convert between types. This PR makes converting nested `T -> [T; 1]` transmutes possible, and `[uB*2; N] -> [uB; N * 2]` possible as well.

I'm not sure whether this is something that would be wanted, and if it is it definitely should not be insta-stable, so I'd add a feature gate.
2023-04-08 19:47:22 +00:00
..
array-impls
auxiliary
backcompat
defaults update tests/ui 2023-04-07 18:07:11 +10:00
early const generic -> const parameter in err msg 2023-02-20 12:58:11 +01:00
generic_arg_infer
generic_const_exprs Bless tidy 2023-03-27 18:58:07 +00:00
infer diagnostics: update test cases to refer to assoc fn with self as method 2023-02-22 08:40:47 -07:00
issues Add regression test for #105821 2023-03-01 22:01:12 +09:00
late-bound-vars
min_const_generics preserve delim spans during macro_rules! expansion if able 2023-01-20 20:16:37 +01:00
occurs-check Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
parser-error-recovery diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
std
type-dependent
apit-with-const-param.rs
arg-in-pat-1.rs
arg-in-pat-2.rs
arg-in-pat-3.rs
argument_order.rs
argument_order.stderr
array-wrapper-struct-ctor.rs
assoc_const_eq_diagnostic.rs
assoc_const_eq_diagnostic.stderr
associated-type-bound-fail.rs
associated-type-bound-fail.stderr
associated-type-bound.rs
bad-const-generic-exprs.rs recover more unbraced const args 2023-01-27 19:26:04 +01:00
bad-const-generic-exprs.stderr recover more unbraced const args 2023-01-27 19:26:04 +01:00
bad-generic-in-copy-impl.rs Suppress copy impl error when post-normalized type references errors 2023-03-08 00:12:33 +00:00
bad-generic-in-copy-impl.stderr Suppress copy impl error when post-normalized type references errors 2023-03-08 00:12:33 +00:00
bad-subst-const-kind.rs Constrain const vars to error if const types are mismatched 2023-03-19 03:45:47 +00:00
bad-subst-const-kind.stderr Constrain const vars to error if const types are mismatched 2023-03-19 03:45:47 +00:00
broken-mir-1.rs
broken-mir-2.rs
cannot-infer-type-for-const-param.rs
coerce_unsized_array.rs
concrete-const-as-fn-arg.rs
concrete-const-impl-method.rs
condition-in-trait-const-arg.rs
const_trait_fn-issue-88433.rs
const-arg-in-const-arg.full.stderr Error code E0794 for late-bound lifetime parameter error. 2023-03-07 21:26:19 +01:00
const-arg-in-const-arg.min.stderr Error code E0794 for late-bound lifetime parameter error. 2023-03-07 21:26:19 +01:00
const-arg-in-const-arg.rs
const-arg-in-fn.rs
const-arg-type-arg-misordered.rs
const-arg-type-arg-misordered.stderr
const-argument-cross-crate-mismatch.rs
const-argument-cross-crate-mismatch.stderr
const-argument-cross-crate.rs
const-argument-if-length.full.stderr
const-argument-if-length.min.stderr
const-argument-if-length.rs
const-argument-non-static-lifetime.min.stderr Remove save-analysis. 2023-02-16 15:14:45 +11:00
const-argument-non-static-lifetime.rs Remove save-analysis. 2023-02-16 15:14:45 +11:00
const-fn-with-const-param.rs
const-generic-default-wont-borrowck.rs
const-generic-default-wont-borrowck.stderr
const-generic-function.rs
const-generic-function.stderr
const-generic-type_name.rs
const-param-after-const-literal-arg.rs
const-param-before-other-params.rs
const-param-before-other-params.stderr
const-param-elided-lifetime.full.stderr
const-param-elided-lifetime.min.stderr Introduce ReError 2023-02-09 10:26:49 +00:00
const-param-elided-lifetime.rs Introduce ReError 2023-02-09 10:26:49 +00:00
const-param-in-async.rs
const-param-type-depends-on-const-param.full.stderr
const-param-type-depends-on-const-param.min.stderr defer array len printing to const arg printing 2023-01-18 04:07:39 +00:00
const-param-type-depends-on-const-param.rs defer array len printing to const arg printing 2023-01-18 04:07:39 +00:00
const-param-type-depends-on-type-param-ungated.rs Remove save-analysis. 2023-02-16 15:14:45 +11:00
const-param-type-depends-on-type-param-ungated.stderr Remove save-analysis. 2023-02-16 15:14:45 +11:00
const-param-type-depends-on-type-param.full.stderr
const-param-type-depends-on-type-param.min.stderr
const-param-type-depends-on-type-param.rs
const-parameter-uppercase-lint.rs
const-parameter-uppercase-lint.stderr
core-types.rs
cross_crate_complex.rs
deref-into-array-generic.rs
different_generic_args_array.rs
different_generic_args_array.stderr
different_generic_args.full.stderr
different_generic_args.min.stderr
different_generic_args.rs
dont-evaluate-array-len-on-err-1.rs
dont-evaluate-array-len-on-err-1.stderr defer array len printing to const arg printing 2023-01-18 04:07:39 +00:00
dyn-supertraits.rs
ensure_is_evaluatable.rs
ensure_is_evaluatable.stderr Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
enum-variants.rs
exhaustive-value.rs
exhaustive-value.stderr
expose-default-substs-param-env.rs
float-generic.adt_const_params.stderr
float-generic.rs
float-generic.simple.stderr
fn_with_two_const_inputs.rs
fn_with_two_const_inputs.stderr Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
fn_with_two_same_const_inputs.rs
fn-const-param-call.full.stderr
fn-const-param-call.min.stderr
fn-const-param-call.rs
fn-const-param-infer.full.stderr
fn-const-param-infer.min.stderr
fn-const-param-infer.rs
forbid-non-structural_match-types.rs
forbid-non-structural_match-types.stderr
foreign-item-const-parameter.rs
foreign-item-const-parameter.stderr
generic-param-mismatch.rs
generic-param-mismatch.stderr
ice-68875.rs
ice-68875.stderr
ice-const-generic-function-return-ty.rs
ice-const-generic-function-return-ty.stderr
impl-const-generic-struct.rs
incorrect-number-of-const-args.rs
incorrect-number-of-const-args.stderr diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
infer_arg_from_pat.rs
infer_arr_len_from_pat.rs
inhabited-assoc-ty-ice-1.rs
inhabited-assoc-ty-ice-2.rs
integer-literal-generic-arg-in-where-clause.rs
intrinsics-type_name-as-const-argument.min.stderr
intrinsics-type_name-as-const-argument.rs
invalid-const-arg-for-type-param.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
invalid-const-arg-for-type-param.stderr diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
invalid-constant-in-args.rs diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
invalid-constant-in-args.stderr diagnostics: remove inconsistent English article "this" from E0107 2023-02-23 10:27:06 -07:00
invalid-enum.rs
invalid-enum.stderr
invariant.rs
invariant.stderr
issue-46511.rs
issue-46511.stderr
issue-66451.rs
issue-66451.stderr
issue-70408.rs
issue-80471.rs
issue-80471.stderr
issue-93647.rs Move const trait bounds checks to MIR constck 2023-03-28 08:39:55 +00:00
issue-93647.stderr Move const trait bounds checks to MIR constck 2023-03-28 08:39:55 +00:00
issue-97007.rs
issue-102124.rs
issue-105689.rs
issue-106419-struct-with-multiple-const-params.rs Added UI test case for issue #106419 2023-01-19 15:39:05 +01:00
legacy-const-generics-bad.rs
legacy-const-generics-bad.stderr
legacy-const-generics.rs
nested-type.full.stderr
nested-type.min.stderr add predicate evaluation logic 2023-02-17 09:32:39 +00:00
nested-type.rs add predicate evaluation logic 2023-02-17 09:32:39 +00:00
outer-lifetime-in-const-generic-default.rs
outer-lifetime-in-const-generic-default.stderr
overlapping_impls.rs
params-in-ct-in-ty-param-lazy-norm.full.stderr
params-in-ct-in-ty-param-lazy-norm.min.stderr
params-in-ct-in-ty-param-lazy-norm.rs
parent_generics_of_encoding_impl_trait.rs
parent_generics_of_encoding_impl_trait.stderr
parent_generics_of_encoding.rs
projection-as-arg-const.rs
projection-as-arg-const.stderr
promotion.rs
raw-ptr-const-param-deref.full.stderr
raw-ptr-const-param-deref.min.stderr
raw-ptr-const-param-deref.rs
raw-ptr-const-param.full.stderr
raw-ptr-const-param.min.stderr
raw-ptr-const-param.rs
slice-const-param-mismatch.full.stderr
slice-const-param-mismatch.min.stderr
slice-const-param-mismatch.rs
slice-const-param.rs
sneaky-array-repeat-expr.rs
sneaky-array-repeat-expr.stderr
struct-with-invalid-const-param.rs
struct-with-invalid-const-param.stderr
suggest_const_for_array.rs
suggest_const_for_array.stderr
trait-const-args.rs
transmute_no_gate.rs Add feature gate 2023-04-07 11:18:07 -07:00
transmute_no_gate.stderr Add feature gate 2023-04-07 11:18:07 -07:00
transmute-const-param-static-reference.min.stderr
transmute-const-param-static-reference.rs
transmute-fail.rs Add feature gate 2023-04-07 11:18:07 -07:00
transmute-fail.stderr Add feature gate 2023-04-07 11:18:07 -07:00
transmute.rs Add feature gate 2023-04-07 11:18:07 -07:00
transparent-maybeunit-array-wrapper.rs
try_unify_ignore_lifetimes.rs
two_matching_preds.rs
type_mismatch.rs Use param's real type in try_eval_lit_or_param 2023-03-09 20:49:11 +00:00
type_mismatch.stderr Note type mismatch on ConstArgHasType 2023-03-23 19:09:34 +00:00
type_not_in_scope.rs Use param's real type in try_eval_lit_or_param 2023-03-09 20:49:11 +00:00
type_not_in_scope.stderr Use param's real type in try_eval_lit_or_param 2023-03-09 20:49:11 +00:00
type_of_anon_const.rs
type-after-const-ok.rs
types-mismatch-const-args.full.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
types-mismatch-const-args.min.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
types-mismatch-const-args.rs
unify_with_nested_expr.rs
unify_with_nested_expr.stderr Specify what 'this' actually is 2023-02-21 05:21:07 +00:00
uninferred-consts-during-codegen-1.rs
uninferred-consts-during-codegen-2.rs
unknown_adt.rs
unknown_adt.stderr
unused_braces.fixed Fix unused_braces on generic const expr macro call 2023-01-14 15:49:08 +00:00
unused_braces.full.fixed
unused_braces.min.fixed
unused_braces.rs Fix unused_braces on generic const expr macro call 2023-01-14 15:49:08 +00:00
unused_braces.stderr Fix unused_braces on generic const expr macro call 2023-01-14 15:49:08 +00:00
unused-const-param.rs
unused-type-param-suggestion.rs
unused-type-param-suggestion.stderr
where-clauses.rs
wrong-normalization.rs Add test for implementation on projection 2023-02-10 14:44:54 +01:00
wrong-normalization.stderr Tighter spans for bad inherent impl types 2023-02-13 18:41:18 +00:00