Add #[rustc_legacy_const_generics] by Amanieu · Pull Request #82447 · rust-lang/rust (original) (raw)

This is the first step towards removing #[rustc_args_required_const]: a new attribute is added which rewrites function calls of the form func(a, b, c) to func::<{b}>(a, c). This allows previously stabilized functions in stdarch which use rustc_args_required_const to use const generics instead.

This new attribute is not intended to ever be stabilized, it is only intended for use in stdarch as a replacement for #[rustc_args_required_const].

#[rustc_legacy_const_generics(1)] pub fn foo(x: usize, z: usize) -> [usize; 3] { [x, Y, z] }

fn main() { assert_eq!(foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]); assert_eq!(foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]); }

r? @oli-obk