Skip to content

Commit 8db50d0

Browse files
committed
Document how to transition between editions
1 parent ef5de6b commit 8db50d0

File tree

1 file changed

+70
-7
lines changed

1 file changed

+70
-7
lines changed

src/editions/transitioning.md

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
11
# Transitioning your code to a new edition
22

3-
In general, to update your code to a new edition, the process
4-
will look like this:
3+
Transitioning between editions is built around lints. Fundamentally, the
4+
process works like this:
55

6-
* Make sure your build is warning-free.
7-
* Update or add the `edition` key in `Cargo.toml`
8-
* Fix any warnings, possibly by running `rustfix`.
6+
* Get your code compiling with no warnings.
7+
* Opt in to the new edition.
8+
* Fix any new warnings that may result.
99

10-
At this time, the `edition` key does not yet work, and `rustfix` is in a
11-
larval state. This section will update as our story gets better here.
10+
Luckily, we've been working on a tool to help assist with this process,
11+
`rustfix`. It can take suggestions from the compiler and automatically
12+
re-write your code to comply with new features and idioms.
13+
14+
> `rustfix` is still quite young, and very much a work in development. But it works
15+
> for the basics! We're working hard on making it better and more robust, but
16+
> please bear with us for now.
17+
18+
## Installing rustfix
19+
20+
You can get `rustfix` from crates.io. Given that you're probably using Cargo,
21+
you'll want to run this:
22+
23+
```shell
24+
$ cargo +nightly install cargo-fix --git https://github.com/killercup/rustfix.git
25+
```
26+
27+
And that's it! Note that you do need a nightly Cargo to use `rustfix` at the
28+
moment; in fact, all of the edition stuff is nightly only for now. Eventually
29+
this will be stable! Same with installing from `git`, for now, it's needed.
30+
31+
## Prepare for the next edition
32+
33+
There are some lints that can help you prepare for the next edition, but
34+
they're not currently turned on by default. `rustfix` has your back
35+
though! To turn them on and have `rustfix` fix up your code, run this:
36+
37+
```shell
38+
$ cargo +nightly fix --prepare-for 2018
39+
```
40+
41+
This would turn on those lints, and fix up the project for the 2018 edition.
42+
If there's something that `rustfix` doesn't know how to fix automatically yet,
43+
the warning will be printed; you'll need to fix those manually. Do so
44+
until you get a run with no warnings.
45+
46+
## Commit to the next edition
47+
48+
Once you're happy with those changes, it's time to use the new edition.
49+
Add this to your `Cargo.toml`:
50+
51+
```toml
52+
cargo-features = ["edition"]
53+
54+
[package]
55+
edition = '2018'
56+
```
57+
58+
That `cargo-features` line should go at the very top; and `edition` goes into
59+
the `[package]` section. As mentioned above, right now this is a nightly-only
60+
feature of Cargo, so you need to enable it for things to work.
61+
62+
At this point, your project should compile with a regular old `cargo build`.
63+
However, since you've said you're using the new edition, you may get more
64+
warnings! Time to bust out `rustfix` again.
65+
66+
## Fix new warnings
67+
68+
To fix up these warnings, we can use `rustfix`:
69+
70+
```shell
71+
$ cargo +nightly fix
72+
```
73+
74+
This will fix up all of the new warnings. Congrats! You're done!

0 commit comments

Comments
 (0)