Radar · Rust · #002 · Week 40 · Sep 28 – Oct 4, 2026
Generic Const Arguments design article
Nice to knowlanguage
- What changed
- The Inside Rust post explains the new “Generic Const Arguments” (GCA) design that will replace the existing
generic_const_exprsfeature. - Production impact
- The source does not say.
- Try it
- Read the article and note the proposed syntax; no code changes are required today.
- Source
- blog.rust-lang.org/inside-rust/2026/10/02/generic-const-args-and-you/
Understand it, then run it
Const generics let you write types that depend on constant values, like struct Array<T, const N: usize>. Today you can only use a plain constant (N) or a fully known value ({ 1 + 1 }). You cannot write something that mixes a generic parameter with a constant expression, such as [u8; T::SIZE] or [u8; N + 1]. The new Generic Const Arguments (GCA) design adds a macro gca! that lets you embed limited expressions involving generic parameters inside const arguments. With gca! you can write Bar<gca!(Foo { field: N })> or accepts::<gca!(TupleStruct(N))>(), enabling array sizes, enum variants, and struct constructions that depend on generic values.
Run it now
// GCA is not yet in Rust 1.98.1, so we cannot use gca!.
// This example shows the current limitation: we cannot form an array size from a generic parameter inside a const expression.
struct Foo<const N: usize>;
fn make_array<const N: usize>() -> [u8; N] {
// Works because the const generic is a plain parameter.
[0; N]
}
// Trying to write something like [u8; T::SIZE] would fail today.
// The following would be a compile error if uncommented:
//
// fn make_from_trait<T: Trait>() -> [u8; T::SIZE] {
// [0; T::SIZE]
// }
//
// The error would be: generic parameters may not be used in const arguments.
fn main() {
// Demonstrate the working case.
let _ = make_array::<5>();
println!("Array of length 5 created successfully.");
}
What it printed when we ran it on Rust 1.98.1 (edition 2024)
Array of length 5 created successfully.
After the change ships
rust · the proposal's code; it does not compile until the change ships
// This code does not compile until the Generic Const Arguments feature ships.
#![feature(gca_adts, adt_const_params)]
use core::gca;
#[derive(ConstParamTy, Eq, PartialEq)]
struct TupleStruct(usize);
fn accepts<const N: TupleStruct>() {}
fn example<const N: usize>() {
accepts::<gca!(TupleStruct(N))>();
}
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-120b from the linked source · claims checked against the sources · human-reviewed