agentleFS
botirkhaltaevbotirkhaltaev/botir-skills/skills/rust-editions/SKILL.md

rust-editions

Skill4 starsChanged 3 months agoApache-2.0View on GitHub

Master Rust editions, migration, and compatibility. Use when migrating between Rust editions (2015, 2018, 2021, 2024), understanding edition differences, using edition-specific features, or updating legacy code.

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Default when edition is omitted from Cargo.toml

    line 38

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Editions

Guide to Rust editions and migration based on The Edition Guide.

When to Use This Skill

  • Migrating between Rust editions
  • Understanding edition differences
  • Using edition-specific features
  • Updating legacy code

Core References

Edition Overview

EditionYearStatus
20152015Stable
20182018Stable
20212021Stable
20242024Stable (RFC 3501, Rust 1.85.0); prefer for new crates

2021 and 2024 are both stable. New Cargo projects typically use 2024. Existing crates may stay on 2021 until migrated.

Edition 2015

Original edition. Key features:

  • Ownership, borrowing, lifetimes
  • Traits and generics
  • Default when edition is omitted from Cargo.toml

Edition 2018

Major improvements:

  • ? for Option and Result
  • Path/module system changes
  • Raw identifiers (r#match)
  • dyn Trait for trait objects
  • New keywords (async, await, dyn, try reserved)
fn foo(x: Option<i32>) -> Option<i32> {
    Some(x? + 1)
}

let r#match = 42;
let x: Box<dyn Trait> = Box::new(Concrete::new());

Edition 2021

Stable edition (still widely used). Key changes:

  • Disjoint closure capture
  • Or-patterns in macro_rules!
  • Prelude adds TryFrom, TryInto, FromIterator
  • IntoIterator for arrays (edition-gated .into_iter() semantics)
  • Panic macro consistency
  • Cargo feature resolver v2 by default
  • Reserved prefixes (ident#… forms)
match value {
    Some(1) | Some(2) | Some(3) => println!("one two or three"),
    _ => println!("other"),
}

Edition 2024

Stable as of Rust 1.85.0 (RFC 3501). Prefer for new crates.

RPIT lifetime capture

Without an explicit use<..> bound, in-scope lifetime parameters are captured in return-position impl Trait (was edition-dependent before). Precise capturing (use<'a, T>) works in all editions since 1.82.

// 2024: captures `'_` implicitly (like async fn / trait RPIT)
fn f(_: &()) -> impl Sized {}

// Opt out of capturing lifetimes when needed:
fn g<'a>(x: &'a ()) -> impl Sized + use<> { *x }

Migrate with cargo fix --edition (impl_trait_overcaptures lint). Prefer use<..> over old Captures / outlives tricks.

if let temporary scope

Temporaries from the if let scrutinee drop before the else branch (shorter than 2021). Avoids common RwLock deadlock patterns; code that relied on long-lived temps may need match instead.

Reserved gen keyword

gen is reserved for future gen blocks (RFC 3513). Identifiers named gen become r#gen via keyword_idents_2024. Gen blocks themselves are not stabilized by the edition.

Unsafe attributes and unsafe extern

These attributes require unsafe(...) in 2024:

  • #[unsafe(no_mangle)]
  • #[unsafe(export_name = "...")]
  • #[unsafe(link_section = "...")]

extern blocks must be unsafe extern "C" { ... } (items can be marked safe / unsafe).

Prelude: Future and IntoFuture

Both are in the 2024 prelude. Method-name collisions (e.g. custom poll) need fully qualified syntax; rust_2024_prelude_collisions migrates them.

IntoIterator for Box<[T]>

IntoIterator for boxed slices exists in all editions (1.80+). Method call .into_iter() yields values in 2024; pre-2024 method resolution still yielded &T. Migration rewrites .into_iter() → .iter() when references were intended (boxed_slice_into_iter).

Other notable 2024 changes

  • Tail-expression temporary scope (block tail temps drop sooner)
  • let chains in if / while
  • unsafe_op_in_unsafe_fn warn-by-default
  • Disallow references to static mut
  • Never-type fallback change
  • Macro fragment specifier tightening
  • Cargo: rust-version-aware resolver; table/key consistency
  • Rustdoc combined doctests; rustfmt style edition

Deeper notes and chapter links: references/edition-2024.md.

Migration

Official flow (Edition Guide):

cargo update
cargo fix --edition
# then edit Cargo.toml:
[package]
edition = "2024"
cargo build   # or cargo test
cargo fmt

cargo fix --edition applies the rust-2024-compatibility lint group against the next edition while your manifest still names the old one; then bump edition = "2024".

Requires a toolchain that supports 2024 (Rust 1.85+).

Common post-migration review

  • RPIT: confirm use<> bounds match intended capture
  • if let → match rewrites: keep only if you need 2021 temp lifetimes
  • Unsafe attrs / unsafe extern: review soundness; autofix cannot verify it
  • Boxed-slice .into_iter() vs .iter()
  • Prelude collisions on poll / into_future

Reference Map

  • references/edition-2015.md — 2015 edition
  • references/edition-2018.md — 2018 edition
  • references/edition-2021.md — 2021 edition
  • references/edition-2024.md — 2024 edition (deep dive + chapter links)
  • references/migration.md — Migration commands and pitfalls

Key Commands

cargo fix --edition
# Cargo.toml: edition = "2024"
cargo build
cargo test
cargo fmt

Key References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.