The feature gate for the issue is #![feature(macroless_generic_const_args)]. Using it requires #![feature(min_generic_const_args)] to be enabled as well.
Background
On stable, there are two kinds of const arguments for generics at the moment:
- "anon consts", which cannot be generic, and support arbitrary expressions. These are opaque to the type system, and are blindly handed off to CTFE to get a concrete value for.
min_const_generics arguments, which are plain paths to const parameters, used in e.g. array lengths (e.g. fn foo<const N: usize>(x: [u32; N]) {}). These are visible to, and reasoned about, by the type system.
The second category, things that can be reasoned about by the type system, have the (bikesheddable) name of a "directly represented" const argument. The generic_const_args family of features is about expanding and reasoning about these directly represented const arguments in various ways.
#![feature(min_generic_const_args)] extends the set of directly represented const arguments with:
- the
direct_const_arg!() macro allows a significantly expanded set of expressions within it, e.g. paths to type const items, paths to regular const items, struct expressions, array expressions, so on and so forth. (Informational note: each of these can be and likely will be under various feature flags, e.g. paths to type const items are supported under min_generic_const_args, but paths to regular const items are only supported under generic_const_args)
Finally, we come to this feature, #![feature(macroless_generic_const_args)]. This feature extends the set of directly represented const arguments with:
- Anything that used to be supported within the
direct_const_arg!() macro is now supported without the macro. Expressions will be attempted to be lowered "directly", and if they cannot be represented directly, it will automatically fall back to being represented as an anon const.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
Unresolved Questions
The logic of "attempt to lower as a directly represented argument, fall back to anon const if we can't" has several fairly sketchy aspects to it. There is a set of expressions that are allowed to be represented directly, and a set that isn't, and we need to cut these two sets apart somehow. How "sharp" this knife doing the cutting is, how fancy we get with it, etc., is an open question. Relevant topics:
- Potential behavior difference to inference (
_) if represented directly or via anon const
- Whether we allow nameres to influence whether an expression is represented directly or falls back to an anon const, or if we require the decision to be made purely on syntax
- for example, under
min_generic_const_args, we could make paths to type consts be represented directly, but paths to regular consts fall back to anon consts
- but if
generic_const_args is enabled, we could make both paths to type consts and paths to regular consts be supported directly
Implementation history
The feature gate for the issue is
#![feature(macroless_generic_const_args)]. Using it requires#![feature(min_generic_const_args)]to be enabled as well.Background
On stable, there are two kinds of const arguments for generics at the moment:
min_const_genericsarguments, which are plain paths to const parameters, used in e.g. array lengths (e.g.fn foo<const N: usize>(x: [u32; N]) {}). These are visible to, and reasoned about, by the type system.The second category, things that can be reasoned about by the type system, have the (bikesheddable) name of a "directly represented" const argument. The generic_const_args family of features is about expanding and reasoning about these directly represented const arguments in various ways.
#![feature(min_generic_const_args)]extends the set of directly represented const arguments with:direct_const_arg!()macro allows a significantly expanded set of expressions within it, e.g. paths totype constitems, paths to regularconstitems, struct expressions, array expressions, so on and so forth. (Informational note: each of these can be and likely will be under various feature flags, e.g. paths totype constitems are supported undermin_generic_const_args, but paths to regularconstitems are only supported undergeneric_const_args)Finally, we come to this feature,
#![feature(macroless_generic_const_args)]. This feature extends the set of directly represented const arguments with:direct_const_arg!()macro is now supported without the macro. Expressions will be attempted to be lowered "directly", and if they cannot be represented directly, it will automatically fall back to being represented as an anon const.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
min_generic_const_argsfeature (allow mGCA const arguments to fall back to anon consts #158617)min_generic_const_args, create a newmacroless_generic_const_argsfeature (implement #![feature(macroless_generic_const_args)] #159058)rustfmtUnresolved Questions
The logic of "attempt to lower as a directly represented argument, fall back to anon const if we can't" has several fairly sketchy aspects to it. There is a set of expressions that are allowed to be represented directly, and a set that isn't, and we need to cut these two sets apart somehow. How "sharp" this knife doing the cutting is, how fancy we get with it, etc., is an open question. Relevant topics:
_) if represented directly or via anon constmin_generic_const_args, we could make paths to type consts be represented directly, but paths to regular consts fall back to anon constsgeneric_const_argsis enabled, we could make both paths to type consts and paths to regular consts be supported directlyImplementation history
min_generic_const_argsgate, not split out into its own feature yet