فا
← BACK TO THE WIRE
N°0432Rust2 MIN3 SOURCES

Rust’s Generic Const Arguments Redraw the Boundary Between Types and Values

A new Rust design consolidates several experimental features for using generic parameters inside const arguments. The payoff is more expressive type-level arrays and data, but the syntax, equality rules, and compiler status are still moving targets.

SHARE
Rust
Rust’s Generic Const Arguments Redraw the Boundary Between Types and Values
IMAGE: AI-GENERATED

Rust’s const generics are gaining a broader experimental design. In an Inside Rust post published on October 2, the Const Generics Project Group described Generic Const Arguments (GCA), a family of features intended to replace the long-running generic_const_exprs experiment.

The practical problem is familiar: stable Rust can use a const parameter such as N or a fully concrete expression, but it cannot generally express type-level values such as [u8; N + 1] or [u8; T::NUM_BYTES]. That gap limits fixed-size abstractions and has pushed some libraries toward type-level-number crates.

GCA approaches the problem by making the supported expression category explicit. With the experimental gca_adts feature, arrays, tuples, structs, and enum values involving generic parameters can be passed through gca!(...). A simplified example is a const argument such as gca!([N, 12]), where N is itself generic. The same design also introduces const-item paths for more indirect cases, including associated constants and generic const items.

That explicitness is a safety and compatibility decision, not merely a syntax preference. The project group says gca!(...) arguments have different rules from ordinary const arguments: they can refer to generic parameters, but they currently support fewer expression forms. Arithmetic and function calls, for example, are not directly accepted inside the macro. Other experimental features can route such expressions through const items.

The hardest issue is equality. Once a value participates in a type, the compiler must decide when two const expressions describe the same type. The current tracking issue describes GCA as relying on definitional equality unless const evaluation can establish a result. It also lists unresolved questions around the boundary between opaque equality and richer future reasoning, such as recognizing mathematical equivalences.

This matters for systems code. A library that encodes packet widths, protocol layouts, or serialized representations in types could eventually express more of its invariants without duplicating arithmetic in runtime code. But public APIs would need careful review: changing whether a const item is transparent or opaque can affect what the compiler can prove about type equality.

The near-term message for Rust developers is therefore “experiment, don’t depend.” GCA is still experimental nightly functionality, and the tracking issue remains open with implementation, documentation, style, and stabilization work listed ahead. The project group also acknowledges that the visible gca!(...) syntax creates ergonomic problems and that the macroless alternatives are not yet recommended.

For developers maintaining generic fixed-size APIs, the useful test is small: try the nightly feature gates in an isolated branch, inspect type-equality failures, and keep a stable-compatible fallback. GCA may become a cleaner foundation for const-heavy abstractions, but today its most important contribution is a clearer design boundary for deciding which compile-time values Rust’s type system is allowed to understand.

TAGSRustconst genericsgeneric const argumentsnightly Rust
Grounded sources3 REFS
  1. [01]Generic Const Args and Youblog.rust-lang.org ↗
  2. [02]Tracking Issue for Generic Const Arguments #151972github.com ↗
  3. [03]RFC 2000: Const Genericsrust-lang.github.io ↗
Read next

Get the wire in your inbox

Every new signal, straight from the generator. No noise, unsubscribe anytime.

RSS AVAILABLE · NO SPAM