Rust 1.51 Lands the Minimum Viable Const Generics
Rust 1.51 ships const generics, a new Cargo feature resolver, and faster macOS builds -- one of the language's biggest additions in years.
Rust 1.51.0 went out on March 25, and the headline feature is one people have been asking for since practically before Rust hit 1.0: const generics. If you haven’t been following the tracking issues, the short version is that types can now be parameterized over constant values – integers, bools, and chars – not just over other types and lifetimes like before.
This sounds abstract until you hit the problem it solves. Arrays in Rust have always been a special case: [T; N] works fine for any specific N, but you couldn’t write generic code over arrays of arbitrary length. Want a trait implemented for [T; 1] through [T; 32]? Before this release, that meant a macro churning out dozens of near-identical impls, which is exactly the kind of thing that made people wince when explaining Rust’s rough edges to newcomers. With const generics, you can write struct Buffer<T, const N: usize> and have N behave like a real type parameter, checked at compile time, monomorphized like everything else.
It’s worth being precise about scope, because the team has been careful to call this a “minimum viable” version. You get const generics for the three primitive-ish kinds – integers, bool, char – and you can use them in fairly straightforward positions. The more ambitious stuff people actually want long-term (const generics over custom struct types, or using expressions like N + 1 in a type position) is still in the const generics working group’s queue. This release is deliberately the floor, not the ceiling. But shipping the floor at all, after years of design churn on the RFC, is the real news. A few library authors have already started sketching out how fixed-size vector and matrix types could drop their macro-generated impls in favor of genuinely generic code.
Two other changes rode along in this release that are easy to overlook next to const generics but matter for day-to-day work. Cargo has a new feature resolver you can opt into, which changes how feature unification works across a dependency graph – specifically aimed at avoiding features leaking into build targets that shouldn’t have them, a longstanding source of confusing build breakage in bigger workspaces. And macOS users get meaningfully faster compile times in this release, which if you’ve sat through a cargo build on a laptop fan spin-up will not need justification.
None of this is going to change what a “hello world” looks like, and the const generics support is intentionally narrow for now. But it’s the kind of foundational piece that unlocks a lot of downstream ergonomics work – embedded and numerics-heavy crates especially stand to benefit once library authors catch up. The community reaction so far has been enthusiastic, with more than a few people calling this the biggest language-level addition since async/await landed. Whether that holds up depends on how fast the working group can push past the “minimum viable” line, but for now, it’s a genuinely good day for anyone who’s been maintaining a pile of macro-generated array impls.