mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
9629b90b3f
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). |
||
---|---|---|
.. | ||
auxiliary | ||
lifetime-errors | ||
anonymize-unnamed-bound-vars-in-binders.rs | ||
bare-trait-object-borrowck.rs | ||
bare-trait-object.rs | ||
borrowck-let-suggestion.rs | ||
borrowck-let-suggestion.stderr | ||
conflicting-bounds.rs | ||
conflicting-bounds.stderr | ||
copy_modulo_regions.rs | ||
copy_modulo_regions.stderr | ||
could-not-resolve-issue-121503.rs | ||
could-not-resolve-issue-121503.stderr | ||
elided-lifetime-in-anon-const.rs | ||
elided-lifetime-in-param-pat.rs | ||
elided-lifetime-in-path-in-impl-Fn.rs | ||
elided-lifetime-in-path-in-pat.rs | ||
elided-lifetime-in-path-in-type-relative-expression.rs | ||
fullwidth-ampersand.rs | ||
fullwidth-ampersand.stderr | ||
issue-17728.rs | ||
issue-17728.stderr | ||
issue-19707.rs | ||
issue-19707.stderr | ||
issue-26638.rs | ||
issue-26638.stderr | ||
issue-34979.rs | ||
issue-34979.stderr | ||
issue-36744-without-calls.rs | ||
issue-54378.rs | ||
issue-55796.rs | ||
issue-55796.stderr | ||
issue-64173-unused-lifetimes.rs | ||
issue-64173-unused-lifetimes.stderr | ||
issue-67498.rs | ||
issue-69314.fixed | ||
issue-69314.rs | ||
issue-69314.stderr | ||
issue-70917-lifetimes-in-fn-def.rs | ||
issue-76168-hr-outlives-2.rs | ||
issue-76168-hr-outlives-3.rs | ||
issue-76168-hr-outlives-3.stderr | ||
issue-76168-hr-outlives.rs | ||
issue-77175.rs | ||
issue-79187-2.rs | ||
issue-79187-2.stderr | ||
issue-79187.rs | ||
issue-79187.stderr | ||
issue-83737-binders-across-types.rs | ||
issue-83737-erasing-bound-vars.rs | ||
issue-83753-invalid-associated-type-supertrait-hrtb.rs | ||
issue-83753-invalid-associated-type-supertrait-hrtb.stderr | ||
issue-83907-invalid-fn-like-path.rs | ||
issue-83907-invalid-fn-like-path.stderr | ||
issue-84398.rs | ||
issue-84604.rs | ||
issue-90170-elision-mismatch.fixed | ||
issue-90170-elision-mismatch.rs | ||
issue-90170-elision-mismatch.stderr | ||
issue-90600-expected-return-static-indirect.rs | ||
issue-90600-expected-return-static-indirect.stderr | ||
issue-91763.rs | ||
issue-91763.stderr | ||
issue-93911.rs | ||
issue-95023.rs | ||
issue-95023.stderr | ||
issue-97193.rs | ||
issue-97193.stderr | ||
issue-97194.rs | ||
issue-97194.stderr | ||
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.fixed | ||
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs | ||
issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.stderr | ||
issue-104432-unused-lifetimes-in-expansion.rs | ||
issue-105227.fixed | ||
issue-105227.rs | ||
issue-105227.stderr | ||
issue-105507.fixed | ||
issue-105507.rs | ||
issue-105507.stderr | ||
issue-105675.rs | ||
issue-105675.stderr | ||
issue-107492-default-value-for-lifetime.rs | ||
issue-107492-default-value-for-lifetime.stderr | ||
issue-107988.rs | ||
issue-107988.stderr | ||
lifetime-bound-will-change-warning.rs | ||
lifetime-bound-will-change-warning.stderr | ||
lifetime-doesnt-live-long-enough.rs | ||
lifetime-doesnt-live-long-enough.stderr | ||
lifetime-elision-return-type-requires-explicit-lifetime.rs | ||
lifetime-elision-return-type-requires-explicit-lifetime.stderr | ||
lifetime-elision-return-type-trait.rs | ||
lifetime-elision-return-type-trait.stderr | ||
lifetime-mismatch-between-trait-and-impl.rs | ||
lifetime-mismatch-between-trait-and-impl.stderr | ||
lifetime-no-keyword.rs | ||
lifetime-no-keyword.stderr | ||
missing-lifetime-in-alias.rs | ||
missing-lifetime-in-alias.stderr | ||
nested-binder-print.rs | ||
nested-binder-print.stderr | ||
nested.rs | ||
no_lending_iterators.rs | ||
no_lending_iterators.stderr | ||
noisy-follow-up-erro.rs | ||
noisy-follow-up-erro.stderr | ||
re-empty-in-error.rs | ||
re-empty-in-error.stderr | ||
refcell-in-tail-expr.edition2021.stderr | ||
refcell-in-tail-expr.rs | ||
shadow.rs | ||
shadow.stderr | ||
shorter-tail-expr-lifetime.edition2021.stderr | ||
shorter-tail-expr-lifetime.rs | ||
suggest-introducing-and-adding-missing-lifetime.fixed | ||
suggest-introducing-and-adding-missing-lifetime.rs | ||
suggest-introducing-and-adding-missing-lifetime.stderr | ||
tail-expr-in-nested-expr.rs | ||
tail-expr-in-nested-expr.stderr | ||
tail-expr-lock-poisoning.rs | ||
temporary-lifetime-extension.rs | ||
undeclared-lifetime-used-in-debug-macro-issue-70152.rs | ||
undeclared-lifetime-used-in-debug-macro-issue-70152.stderr | ||
unnamed-closure-doesnt-life-long-enough-issue-67634.rs | ||
unnamed-closure-doesnt-life-long-enough-issue-67634.stderr | ||
unusual-rib-combinations.rs | ||
unusual-rib-combinations.stderr |