Skip to content

Commit 7c4d99a

Browse files
committed
Tweak and update the transition guide
* Reflect that `rustfix` is now just `cargo fix` and distributed directly with Cargo. * Update that enabling the 2018 edition doesn't enable any warnings, but mention the `rust_2018_idioms` lint which does indeed enable warnings. * Tweak some wording here and there with recent tweaks to the workflow
1 parent 66e72b9 commit 7c4d99a

File tree

2 files changed

+54
-74
lines changed

2 files changed

+54
-74
lines changed

src/editions/index.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,6 @@ You only need to upgrade if you want to take advantage of such features.
4242
## Trying out the 2018 edition
4343

4444
At the time of writing, there are two editions: 2015 and 2018. 2015 is today's
45-
Rust; Rust 2018 will ship later this year. To give Rust 2018 a try, you can
46-
add this feature to your crate root:
47-
48-
```rust
49-
// Opt in to unstable features expected for Rust 2018
50-
#![feature(rust_2018_preview)]
51-
52-
// Opt in to warnings about new 2018 idioms
53-
#![warn(rust_2018_idioms)]
54-
```
55-
56-
and opt in to the new edition in your `Cargo.toml`:
57-
58-
```toml
59-
cargo-features = ["edition"]
60-
61-
[package]
62-
edition = '2018'
63-
```
64-
65-
Like all `#![feature(..)]` flags, this will only work on nightly Rust.
66-
When nightly compilers are released, more functionality is enabled,
67-
so you may experience new warnings, features, and other things.
68-
This is something to keep in mind and is exactly why nightly is unstable!
45+
Rust; Rust 2018 will ship later this year. To transition to the 2018 edition
46+
from the 2015 edition, you'll want to get started with the [transition
47+
guide](editions/transitioning.html).

src/editions/transitioning.md

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
11
# Transitioning your code to a new edition
22

3-
Transitioning between editions is built around lints. Fundamentally, the
4-
process works like this:
3+
New editions might change the way you write Rust -- they add syntax, language,
4+
and library features but also remove others. For example, `async`/`await` will
5+
be available in Rust 2018, but not Rust 2015. Despite this it's our intention
6+
that the migration to new editions is as smooth an experience as possible. It's
7+
considered a bug if it's difficult to upgrade your crate to a new edition. If
8+
you have a difficult time then a bug should be filed with Rust itself.
59

10+
Transitioning between editions is built around compiler lints. Fundamentally,
11+
the process works like this:
12+
13+
* Turn on lints to indicate where code is incompatible with a new edition
614
* Get your code compiling with no warnings.
7-
* Opt in to the new edition.
8-
* Fix any new warnings that may result.
15+
* Opt in to the new edition, code should compile.
16+
* Optionally, enable lints about *idiomatic* code in the new edition.
917

1018
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 GitHub, and eventually, `crates.io`. Given that you're probably using Cargo,
21-
you'll want to run this:
22-
23-
```shell
24-
$ cargo install cargo-fix
25-
```
26-
27-
And that's it!
28-
29-
## Prepare for the next edition
30-
31-
Before we talk about how to move to the new edition, a reminder:
19+
`cargo fix`. It can take suggestions from the compiler and automatically
20+
re-write your code to comply with new features and idioms, drastically reducing
21+
the number of warnings you need to fix manually!
3222

23+
> `cargo fix` is still quite young, and very much a work in development. But it
24+
> works for the basics! We're working hard on making it better and more robust,
25+
> but please bear with us for now.
3326
34-
* New editions might change the way you write Rust -- they add syntax,
35-
language, and library features but also remove others. For example,
36-
`async`/`await` is available in Rust 2018, but not Rust 2015.
37-
* It's our intention that the migration to new editions is as smooth an experience
38-
as possible. It's considered a bug if it's difficult to upgrade your crate to
39-
a new edition. If you have a difficult time then a bug should be filed
40-
with either rustfix or Rust itself.
41-
42-
With that out of the way, let's get into it!
43-
44-
### The preview period
27+
## The preview period
4528

4629
First, editions have a "preview" phase. This lets you try out the new edition
4730
in nightly Rust. During the preview, there's an extra step you need to take
@@ -57,20 +40,22 @@ This will ensure that you're enabling all of the relevant features. Note that
5740
during the time the preview is available, we may continue to add/enable new
5841
features with this flag!
5942

60-
### Running rustfix
43+
## Fix edition compatibility warnings
6144

62-
There are some lints that can help you prepare for the next edition, but
63-
they're not currently turned on by default. `rustfix` has your back though!
64-
To turn them on and have `rustfix` fix up your code, run this:
45+
Next up is to enable compiler warnings about code which is incompatible with the
46+
new 2018 edition. This is where the handy `cargo fix` tool comes into the
47+
picture. To enable the compatibility lints for your project you run:
6548

6649
```shell
67-
$ cargo +nightly fix --prepare-for 2018
50+
$ cargo +nightly fix --prepare-for 2018 --all-targets
6851
```
6952

70-
This would turn on those lints, and fix up the project for the 2018 edition.
71-
If there's something that `rustfix` doesn't know how to fix automatically yet,
72-
the usual compiler warning will be printed; you'll need to fix those
73-
manually. Do so until you get a run with no warnings.
53+
This will instruct Cargo to compile all targets in your project (libraries,
54+
binaries, tests, etc.) and prepare them for the 2018 edition. Cargo will likely
55+
automatically fix a number of files, informing you as it goes along.
56+
57+
If Cargo can't automatically fix everything it'll print out the remaining
58+
warnings. Continue to run the above command until all warnings have been solved.
7459

7560
## Commit to the next edition
7661

@@ -89,15 +74,31 @@ the `[package]` section. As mentioned above, right now this is a nightly-only
8974
feature of Cargo, so you need to enable it for things to work.
9075

9176
At this point, your project should compile with a regular old `cargo +nightly
92-
build`. However, since you've said you're using the new edition, you may get
93-
more warnings! Time to bust out `rustfix` again.
77+
build`. If it does not, this is a bug! Please [file an issue][issue].
78+
79+
[issue]: https://github.com/rust-lang/rust/issues/new
80+
81+
## Writing idiomatic code in a new edition
9482

95-
## Fix new warnings
83+
Your crate has now entered the 2018 edition of Rust, congrats! Recall though
84+
that Editions in Rust signify a shift in idioms over time, and while much old
85+
code will continue to compile it might be written with different idioms today.
86+
87+
An optional next step you can take is to update your code to be idiomatic within
88+
the new edition. This is done with a different set of "idiom lints". To enable
89+
these lints add this to your `lib.rs` or `main.rs`:
90+
91+
```rust
92+
#![warn(rust_2018_idioms)]
93+
```
9694

97-
To fix up these warnings, we can use `rustfix`:
95+
and then execute:
9896

9997
```shell
10098
$ cargo +nightly fix
10199
```
102100

103-
This will try to fix up all of the new warnings. Congrats! You're done!
101+
As before Cargo will automatically fix as much as it can, but you may also need
102+
to fix some warnings manually. Once all warnings have been solved you're not
103+
only compiling with the 2018 edition but you're also already writing idiomatic
104+
2018 code!

0 commit comments

Comments
 (0)