Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

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],
}
}