Rust automatically upgrade to a new edition

Every two or three years, the Rust team produces a new Rust edition. Each edition contains a lot of changes. Each edition brings together the features that have landed into a clear package with fully updated documentation and tooling.

The edition key in Cargo.toml indicates which edition the compiler should use for your code. If the key doesn’t exist, Rust uses 2015 as the edition value for backward compatibility reasons.

Most features will be available on all editions. Developers using any Rust edition will continue to see improvements as new stable releases are made. However, in some cases, mainly when new keywords are added, some new features might only be available in later editions. You will need to switch editions if you want to take advantage of such features.

You can use the cargo fix command to transition your code between different Rust editions. It will update your source code so that it is compatible with the next edition. You might need to set the edition field to the next edition in your Cargo.toml first.

$ cargo fix

For example from The edition book, transitioning from the 2015 edition to the 2018 edition. This code bellow uses an anonymous parameter, that i32, This is not supported in Rust 2018, so this would fail to compile.

trait Foo {
    fn foo(&self, i32);
}

After run the cargo fix:

trait Foo {
    fn foo(&self, _: i32);
}
Rust 🦀Rust