Skip to content
Latchkey

Rust Edition Migration Errors (cargo fix --edition) in CI

You bumped edition in Cargo.toml, and code that compiled under the old edition now fails - editions change defaults like trait-object syntax, closure captures, or array iteration. The migration needs the automated cargo fix --edition pass plus a few manual fixes.

What this error means

Right after raising the edition (e.g. 2018→2021 or 2021→2024), the build fails with errors about bare dyn trait objects, IntoIterator on arrays, panic macro consistency, or disjoint closure captures. The same code built fine on the previous edition.

cargo output
error[E0782]: trait objects must include the `dyn` keyword
 --> src/lib.rs:7:21
  |
7 |     fn handler() -> Box<Handler> { ... }
  |                         ^^^^^^^
  = note: this was allowed before edition 2021

Common causes

Edition-changed defaults and lints

Each edition tightens defaults - dyn becomes required, array IntoIterator yields values, panic macros must be consistent, closures capture disjointly. Old code that relied on the prior behavior errors.

Skipping the automated migration step

cargo fix --edition rewrites most idiom changes for you. Bumping edition by hand without running it leaves the code in the old style the new edition rejects.

How to fix it

Run the automated edition migration

Let cargo apply the mechanical fixes for the new edition, then bump edition.

Terminal
cargo fix --edition --allow-dirty
# then set edition in Cargo.toml:
# [package]
# edition = "2024"
cargo build

Clean up the remaining manual cases

  1. Add dyn to any bare trait objects the migration flagged.
  2. Review array iteration where IntoIterator now yields values, not references.
  3. Re-run cargo build and address any edition-specific errors cargo fix couldn’t auto-resolve.

How to prevent it

  • Use cargo fix --edition to migrate rather than hand-editing the edition.
  • Migrate one edition at a time and commit between steps.
  • Run cargo clippy after a migration to catch idiom regressions.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →