« All posts

Rust's 2026 Goal: Derive-Free Compile-Time Reflection via Const fn

Rust Project's 2026 goals detail a const fn-based compile-time reflection system enabling derive-free serialization and introspection.

As part of its 2026-2028 project goals, the Rust Project is working to finish a const fn-based compile-time type reflection scheme that would let code like serialize(&my_struct) work without derive macros. The plan centers on a TypeId::info() API exposing a Type struct, letting general-purpose crates (serializers, loggers, game engines like bevy) process arbitrary types without requiring trait bounds or ecosystem-wide derive adoption.

The proposal introduces a #[rustc_comptime] (or #[compile_time_only]) attribute restricting certain const fn to compile-time-only calls, since a runtime-callable version would require a global TypeId-to-representation table — deemed infeasible. Basic reflection data structures would land in libcore. Notably, this effort only targets producing const-eval values, not reintroducing types into the type system; that would be a separate follow-up RFC.

Design principles favor procedural const-eval over associated-const DSLs, preserve field privacy, and avoid new semver hazards. The MVP has already landed with weekly additions to supported TypeKind variants, and the team is seeking medium-to-large support from the compiler, lang, libs-api, and types teams to push toward an RFC.