|
| 1 | +--- |
| 2 | +title: "Help test Rust 2018" |
| 3 | +--- |
| 4 | + |
| 5 | +Back in July, we talked about ["Rust 2018"]. In short, we are launching a |
| 6 | +cycle of long-term milestones called "Editions". Editions are a way to |
| 7 | +capture the progress delivered incrementally by our ordinary six-week release |
| 8 | +cycle -- and focus Rust libraries, tooling, and documentation cohesively |
| 9 | +around it. Editions will be selected roughly every three years: Rust 1.0 was |
| 10 | +"Rust 2015" and Rust 1.31 will be "Rust 2018". Each edition has a theme; |
| 11 | +Rust 2015's was "stability", and Rust 2018's is "productivity." |
| 12 | + |
| 13 | +We've been [testing Rust 2018 for a while already], and things are looking |
| 14 | +pretty good! We have just under six weeks until Rust 1.31 ships, and so |
| 15 | +we'd appreciate it if you could give the beta a try. |
| 16 | + |
| 17 | +There's two ways to try out Rust 2018: updating an existing project, and |
| 18 | +starting a new one. For full details, please check out the [Edition Guide], |
| 19 | +but the rest of this post is a quickstart to make it even easier. In |
| 20 | +addition, we have some new lints we'd like you to try; they're described at |
| 21 | +the very end of the post. |
| 22 | + |
| 23 | +If anything goes wrong, or is confusing, please [file an issue] and let us |
| 24 | +know. We want to make sure this is an extra-awesome release! Thank you for |
| 25 | +helping us make Rust even better. <3 |
| 26 | + |
| 27 | +["Rust 2018"]: https://blog.rust-lang.org/2018/07/27/what-is-rust-2018.html |
| 28 | +[testing Rust 2018 for a while already]: https://internals.rust-lang.org/t/rust-2018-release-schedule-and-extended-beta/8076 |
| 29 | +[Edition Guide]: https://rust-lang-nursery.github.io/edition-guide/ |
| 30 | +[file an issue]: https://github.com/rust-lang/rust/issues/new |
| 31 | + |
| 32 | +## Setup: install Rust beta |
| 33 | + |
| 34 | +First things first, you'll need to install the beta release channel of Rust. |
| 35 | +With [Rustup], it's as easy as: |
| 36 | + |
| 37 | +```console |
| 38 | +$ rustup install beta |
| 39 | +``` |
| 40 | + |
| 41 | +To use this channel of Rust instead of your default, you can append a `+beta` |
| 42 | +to any `rustc` or cargo commands: |
| 43 | + |
| 44 | +```console |
| 45 | +$ rustc +beta --version |
| 46 | +$ cargo +beta build |
| 47 | +``` |
| 48 | + |
| 49 | +This lets you stick to stable as the default, while using beta for your |
| 50 | +experiments. |
| 51 | + |
| 52 | +[Rustup]: https://www.rust-lang.org/en-US/install.html |
| 53 | + |
| 54 | +## Start a new project |
| 55 | + |
| 56 | +To start a new project with Rust 2018: |
| 57 | + |
| 58 | +```console |
| 59 | +$ cargo +beta new my-sample-project |
| 60 | +``` |
| 61 | + |
| 62 | +Nothing changes! Well, something changed. Check out `Cargo.toml`: |
| 63 | + |
| 64 | +```toml |
| 65 | +[package] |
| 66 | +name = "my-sample-project" |
| 67 | +version = "0.1.0" |
| 68 | +authors = [ "Your Name <[email protected]>"] |
| 69 | +edition = "2018" |
| 70 | + |
| 71 | +[dependencies] |
| 72 | +``` |
| 73 | + |
| 74 | +That new `edition = "2018"` key/value pair means you're working with Rust 2018. |
| 75 | +If it doesn't exist, it's the same as `edition = "2015"`, so all |
| 76 | +existing projects keep working. |
| 77 | + |
| 78 | +## Convert an existing project |
| 79 | + |
| 80 | +You can also convert an existing project to Rust 2018. Remember, none of your |
| 81 | +dependencies need to be updated for this to work; Rust 2018 and 2015 |
| 82 | +interoperate seamlessly! |
| 83 | + |
| 84 | +The first step is to run `cargo fix`: |
| 85 | + |
| 86 | +```console |
| 87 | +$ cargo fix --edition |
| 88 | +``` |
| 89 | + |
| 90 | +This will check your code, and automatically fix any issues that it can. |
| 91 | +`cargo fix` is still pretty new, and so it can't always fix your code |
| 92 | +automatically. If `cargo fix` can't fix something, it will print the warning |
| 93 | +that it cannot fix to the console. If you see one of these warnings, you'll |
| 94 | +have to update your code manually. See the corresponding section of the |
| 95 | +edition guide for help, and if you have problems, please seek help at the |
| 96 | +user's forums. |
| 97 | + |
| 98 | +Keep running `cargo fix --edition` until you have no more warnings. |
| 99 | + |
| 100 | +Congrats! Your code is now valid in both Rust 2015 and Rust 2018! |
| 101 | + |
| 102 | +Once this is done, you can commit to Rust 2018 by updating |
| 103 | +your `Cargo.toml`: |
| 104 | + |
| 105 | +```toml |
| 106 | +[package] |
| 107 | +name = "my-sample-project" |
| 108 | +version = "0.1.0" |
| 109 | +authors = [ "Your Name <[email protected]>"] |
| 110 | +edition = "2018" |
| 111 | + |
| 112 | +[dependencies] |
| 113 | +``` |
| 114 | + |
| 115 | +See that `edition = "2018"`? That's what opts you in to the new features. |
| 116 | +Set it, `cargo +beta build`, and you should be good to go! |
0 commit comments