macroless_generic_const_args
Enables using #![feature(min_generic_const_args)] without the direct_const_arg! macro.
The tracking issue for this feature is: #159006
Warning: This feature is incomplete; its design and syntax may change.
Related features:
- min_generic_const_args. See that doc for what the
direct_const_arg!is. This feature enables support for directly represented const arguments without the macro. - macroless_const_item_generic_const_args. For a version of this feature that works for const arguments as the right hand side of a const item.
Examples
Here is an example from min_generic_const_args:
#![allow(unused)]
#![allow(incomplete_features)]
#![feature(min_generic_const_args)]
fn main() {
trait Bar {
#[rustc_always_gca]
const VAL: usize;
#[rustc_always_gca]
const VAL2: usize;
}
struct Baz;
impl Bar for Baz {
const VAL: usize = core::direct_const_arg!(2);
const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 });
}
struct Foo<B: Bar> {
arr1: [usize; core::direct_const_arg!(B::VAL)],
arr2: [usize; core::direct_const_arg!(B::VAL2)],
}
}
Using #![feature(macroless_generic_const_args)] enables you to write the above without the macro:
#![allow(unused)]
#![allow(incomplete_features)]
#![feature(min_generic_const_args, macroless_generic_const_args)]
fn main() {
trait Bar {
#[rustc_always_gca]
const VAL: usize;
#[rustc_always_gca]
const VAL2: usize;
}
struct Baz;
impl Bar for Baz {
// note these still need a macro, macroless for these is `macroless_const_item_generic_const_args`
const VAL: usize = core::direct_const_arg!(2);
const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 });
}
struct Foo<B: Bar> {
arr1: [usize; B::VAL],
arr2: [usize; B::VAL2],
}
}