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.
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 2021Common 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.
cargo fix --edition --allow-dirty
# then set edition in Cargo.toml:
# [package]
# edition = "2024"
cargo buildClean up the remaining manual cases
- Add
dynto any bare trait objects the migration flagged. - Review array iteration where
IntoIteratornow yields values, not references. - Re-run
cargo buildand address any edition-specific errors cargo fix couldn’t auto-resolve.
How to prevent it
- Use
cargo fix --editionto migrate rather than hand-editing the edition. - Migrate one edition at a time and commit between steps.
- Run
cargo clippyafter a migration to catch idiom regressions.