Rust 2024 Edition Released - Language Evolution and New Features

2025.12.15

What is Rust 2024 Edition

In February 2025, Rust 2024 Edition was released alongside Rust 1.85. This is the first new edition in 3 years, featuring significant language improvements and ergonomic enhancements.

Reference: The Rust Edition Guide

Major New Features

1. gen blocks (Generators)

Create iterators more intuitively.

// Traditional approach
fn fibonacci() -> impl Iterator<Item = u64> {
    let mut a = 0;
    let mut b = 1;
    std::iter::from_fn(move || {
        let result = a;
        (a, b) = (b, a + b);
        Some(result)
    })
}

// Rust 2024: gen blocks
fn fibonacci() -> impl Iterator<Item = u64> {
    gen {
        let mut a = 0u64;
        let mut b = 1;
        loop {
            yield a;
            (a, b) = (b, a + b);
        }
    }
}

2. async closures

Async closures are now officially supported.

// Previously required workarounds
let fetch = |url| async move {
    reqwest::get(url).await
};

// Rust 2024: Native async closure
let fetch = async |url: &str| {
    reqwest::get(url).await
};

// AsyncFn trait available
async fn process<F>(f: F)
where
    F: AsyncFn(&str) -> Result<Response, Error>
{
    f("https://example.com").await
}

Reference: Rust Async Book

3. New Prelude

Future and IntoFuture added to the prelude.

// Explicit import no longer needed
// use std::future::Future; // Not needed

async fn example() -> impl Future<Output = i32> {
    async { 42 }
}

4. RPIT (Return Position Impl Trait) Improvements

Return types are now more flexible.

// RPIT lifetime capture rules
fn process<'a>(data: &'a str) -> impl Iterator<Item = &'a str> {
    data.split(',')
}

// Rust 2024: + use<> for explicit lifetime specification
fn process<'a>(data: &'a str) -> impl Iterator<Item = &str> + use<'a> {
    data.split(',')
}

Language Changes

1. if/while let Temporary Variable Scope

// Rust 2024: More intuitive scope
if let Some(guard) = lock.lock() {
    // guard's scope ends here
}
// lock is released here (deadlock prevention)

2. Explicit unsafe Attributes

// Unsafe attributes require explicit specification
#[unsafe(no_mangle)]
pub extern "C" fn my_function() {}

#[unsafe(link_section = ".custom")]
static DATA: [u8; 4] = [0; 4];

3. static mut Deprecated

// Deprecated
static mut COUNTER: u32 = 0;

// Recommended: Use SyncUnsafeCell
use std::cell::SyncUnsafeCell;
static COUNTER: SyncUnsafeCell<u32> = SyncUnsafeCell::new(0);

Reference: Rust Reference

Toolchain Improvements

Cargo Improvements

# Cargo.toml
[package]
name = "my-project"
version = "0.1.0"
edition = "2024"  # New edition

# New feature: dev-dependencies separated by default
[dev-dependencies]
criterion = "0.5"
# Formatter improvements
cargo fmt -- --edition 2024

# Clippy new lints
cargo clippy -- -W rust-2024-idioms

rustfmt 2024 Style

// New formatting style
let result = some_function(
    very_long_argument_1,
    very_long_argument_2,
);

// Chain method formatting improvements
let output = input
    .iter()
    .filter(|x| x.is_valid())
    .map(|x| x.transform())
    .collect::<Vec<_>>();

Migration

Automatic Migration

# Update edition
cargo fix --edition

# Verify changes
cargo check

# Address new warnings
cargo clippy --fix

Cargo.toml Update

[package]
edition = "2024"
rust-version = "1.85"

Reference: Rust Blog - Edition 2024

Performance Improvements

Compile Time

ItemRust 2021Rust 2024
Full buildBaseline-15%
IncrementalBaseline-25%
Link timeBaseline-20%

Runtime Optimization

// Compiler optimizes more aggressively
#[inline(always)]
fn hot_path(x: u32) -> u32 {
    // LLVM optimization improvements
    // generate more efficient code
    x.wrapping_mul(31).wrapping_add(17)
}

Ecosystem Support

Major Crate Support Status

Crate2024 Edition Support
tokioSupported
serdeSupported
actix-webSupported
axumSupported
dieselSupported

Summary

Rust 2024 Edition significantly improves language expressiveness and usability.

  • gen blocks: Simplified iterator creation
  • async closures: Improved async programming
  • Enhanced safety: Explicit unsafe attributes
  • Toolchain: Reduced compile times

Existing projects can easily migrate with cargo fix --edition.

← Back to list