Recipe
Move a crate to edition 2024
Use when: a crate you own is on edition 2021 or older and you want the 2024 rules
Goal: the same program on edition 2024, building, tested and reviewed
Taught in Migrating to edition 2024
Quick recipe
-
1
Run
cargo update, build and test, and commit so the tree is clean.Why: newer dependency releases often fix edition problems of their own, and cargo fix refuses to edit uncommitted files.
-
2
Leave the
editionline alone and runcargo fix --edition. It fixes every target (library, binaries, tests, examples) by default. For a crate with Cargo features, add--all-features, and for code behind#[cfg(windows)]-style conditions, run it again with--targetfor those platforms, so every file is compiled and fixed.Example
Fixed src/main.rs (6 fixes)fortidewatch.Why: the fixing lints run under the current edition and rewrite code to mean the same thing under the next one.
-
3
Set
edition = "2024"inCargo.toml(and raiserust-versionto at least 1.85 if it's lower).Why: the tool never changes the line itself, and Cargo refuses a 2024 crate whose rust-version is below 1.85.
-
4
Run
cargo build,cargo test,cargo clippyandcargo fmt, and fix anything left by hand, such asstatic mutreferences.Why: some changes have no automatic fix, and the tests confirm the meaning didn't move.
-
5
Read the diff: check each new
unsafe, replace eachFIXME, and decide whether to keep eachuse<..>andr#name.Why: the tool preserves meaning; it can't judge whether the code's promises are true.