Skip to content

Commit b24ba0c

Browse files
authored
Merge pull request #350 from ehuss/update-dependencies
Update the transitioning steps
2 parents 06ff078 + 972284c commit b24ba0c

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/editions/transitioning-an-existing-project-to-a-new-edition.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Rust includes tooling to automatically transition a project from one edition to
44
It will update your source code so that it is compatible with the next edition.
55
Briefly, the steps to update to the next edition are:
66

7-
1. Run `cargo fix --edition`
8-
2. Edit `Cargo.toml` and set the `edition` field to the next edition, for example `edition = "2024"`
9-
3. Run `cargo build` or `cargo test` to verify the fixes worked.
7+
1. Run `cargo update` to update your dependencies to the latest versions.
8+
2. Run `cargo fix --edition`
9+
3. Edit `Cargo.toml` and set the `edition` field to the next edition, for example `edition = "2024"`
10+
4. Run `cargo build` or `cargo test` to verify the fixes worked.
11+
5. Run `cargo fmt` to reformat your project.
1012

1113
The following sections dig into the details of these steps, and some of the issues you may encounter along the way.
1214

@@ -32,6 +34,16 @@ This code uses an anonymous parameter, that `i32`. This is [not
3234
supported in Rust 2018](../rust-2018/trait-system/no-anon-params.md), and
3335
so this would fail to compile. Let's get this code up to date!
3436

37+
## Updating your dependencies
38+
39+
Before we get started, it is recommended to update your dependencies. Some dependencies, particularly some proc-macros or dependencies that do build-time code generation, may have compatibility issues with newer editions. New releases may have been made since you last updated which may fix these issues. Run the following:
40+
41+
```console
42+
cargo update
43+
```
44+
45+
After updating, you may want to run your tests to verify everything is working. If you are using a source control tool such as `git`, you may want to commit these changes separately to keep a logical separation of commits.
46+
3547
## Updating your code to be compatible with the new edition
3648

3749
Your code may or may not use features that are incompatible with the new edition.
@@ -77,12 +89,33 @@ edition = "2018"
7789
If there's no `edition` key, Cargo will default to Rust 2015. But in this case,
7890
we've chosen `2018`, and so our code will compile with Rust 2018!
7991

92+
## Testing your code in the new edition
93+
8094
The next step is to test your project on the new edition.
8195
Run your project tests to verify that everything still works, such as running [`cargo test`].
8296
If new warnings are issued, you may want to consider running `cargo fix` again (without the `--edition` flag) to apply any suggestions given by the compiler.
8397

98+
At this point, you may still need to do some manual changes. For example, the automatic migration does not update doctests, and build-time code generation or macros may need manual updating. See the [advanced migrations chapter] for more information.
99+
84100
Congrats! Your code is now valid in both Rust 2015 and Rust 2018!
85101

102+
[advanced migrations chapter]: advanced-migrations.md
103+
104+
## Reformatting with rustfmt
105+
106+
If you use [rustfmt] to automatically maintain formatting within your project, then you should consider reformatting using the new formatting rules of the new edition.
107+
108+
Before reformatting, if you are using a source control tool such as `git`, you may want to commit all the changes you have made up to this point before taking this step. It can be useful to put formatting changes in a separate commit, because then you can see which changes are just formatting versus other code changes, and also possibly ignore the formatting changes in `git blame`.
109+
110+
```console
111+
cargo fmt
112+
```
113+
114+
See the [style editions chapter] for more information.
115+
116+
[rustfmt]: https://github.com/rust-lang/rustfmt
117+
[style editions chapter]: ../rust-2024/rustfmt-style-edition.md
118+
86119
## Migrating to an unstable edition
87120

88121
After an edition is released, there is roughly a three year window before the next edition.

0 commit comments

Comments
 (0)