Radar · Rust · Archive · Week 11 · Mar 10 – 16, 2025
Inferred const generic arguments: Call for Testing!
Worth knowinglanguage
- What changed
- The Rust team announced a new feature that allows const generic arguments to be inferred, and they are calling for community testing.
- Production impact
- The source does not say.
- Try it
- Write a small program that uses an inferred const generic argument and compile it with the nightly toolchain.
- Source
- blog.rust-lang.org/inside-rust/2025/03/05/inferred-const-generic-arguments.html
Understand it, then run it
Rust lets you write types that depend on a constant value, like an array size. Before this change you always had to write that constant explicitly, even if the compiler could figure it out. The new feature will let the compiler guess the constant for you, so you can omit it in many places. The announcement is a call for people to try it out and report any problems.
Run it now
// This program demonstrates the current requirement to specify const generic arguments.
// In Rust 1.98.1 (edition 2024) const generics cannot be inferred, so the compiler
// demands the value be written explicitly. The feature is not yet shipped.
struct Array<T, const N: usize> {
data: [T; N],
}
fn main() {
// We must write the size 5 explicitly; otherwise the compiler errors.
let a = Array::<i32, 5> { data: [0; 5] };
println!("Array length: {}", a.data.len());
}
What it printed when we ran it on Rust 1.98.1 (edition 2024)
Array length: 5
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-20b from the linked source · claims checked against the sources · archive, not individually reviewed