keyword

Rust gen: reserved keyword in Edition 2024

Rust 2024 reserves `gen` for future language syntax. It cannot be used as a bare identifier in that edition. Existing code can use a raw identifier with the r# prefix when migrating. This example does not use generator blocks. Expected output: 12 Why: The raw identifier lets the program retain the name gen without using it as a keyword. Common mistake: Reserved status is not proof that generator blocks are available on stable Rust 1.85.0.

Formal Syntax & Structure

rust syntaxrust
let r#gen = expression;

Working Example

Example Snippetrust
fn main() {    let r#gen = 12;    println!("{}", r#gen);}
Rust Reference