|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.24" |
| 4 | +author: The Rust Core Team |
| 5 | +--- |
| 6 | + |
| 7 | +The Rust team is happy to announce a new version of Rust, 1.24.0. Rust is a |
| 8 | +systems programming language focused on safety, speed, and concurrency. |
| 9 | + |
| 10 | +If you have a previous version of Rust installed via rustup, getting Rust |
| 11 | +1.24.0 is as easy as: |
| 12 | + |
| 13 | +```bash |
| 14 | +$ rustup update stable |
| 15 | +``` |
| 16 | + |
| 17 | +If you don't have it already, you can [get `rustup`][install] from the |
| 18 | +appropriate page on our website, and check out the [detailed release notes for |
| 19 | +1.24.0][notes] on GitHub. |
| 20 | + |
| 21 | +[install]: https://www.rust-lang.org/install.html |
| 22 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1240-2018-02-15 |
| 23 | + |
| 24 | +## What's in 1.24.0 stable |
| 25 | + |
| 26 | +This release contains two very exciting new features: `rustfmt` and incremental compilation! |
| 27 | + |
| 28 | +#### `rustfmt` |
| 29 | + |
| 30 | +For years now, we've wanted a tool that automatically can reformat your Rust code to some sort |
| 31 | +of "standard style." With this release, we're happy to announce that a *preview* of `rustfmt` |
| 32 | +can be used with 1.24 stable. To give it a try, do this: |
| 33 | + |
| 34 | +```bash |
| 35 | +$ rustup component add rustfmt-preview |
| 36 | +``` |
| 37 | + |
| 38 | +There are two important aspects here: first, you're using `rustup component |
| 39 | +add` instead of `cargo install` here. If you've previously used `rustfmt` via |
| 40 | +`cargo install`, you should uninstall it first. Second, this is a preview, as |
| 41 | +it says in the name. `rustfmt` is not at 1.0 yet, and some stuff is being |
| 42 | +tweaked, and bugs are being fixed. Once `rustfmt` hits 1.0, we'll be |
| 43 | +releasing a `rustfmt` component and deprecating `rustfmt-preview`. |
| 44 | + |
| 45 | +In the near future, we plan on writing a post about this release strategy, as it's big |
| 46 | +enough for its own post, and is broader than just this release. |
| 47 | + |
| 48 | +For more, please check out [`rustfmt` on GitHub](https://github.com/rust-lang-nursery/rustfmt). |
| 49 | + |
| 50 | +#### Incremental compilation |
| 51 | + |
| 52 | +Back in September of 2016 (!!!), we blogged about [Incremental Compilation](https://blog.rust-lang.org/2016/09/08/incremental.html). |
| 53 | +While that post goes into the details, the idea is basically this: when you're working on |
| 54 | +a project, you often compile it, then change something small, then compile again. Historically, |
| 55 | +the compiler has compiled your *entire* project, no matter how little you've changed the code. |
| 56 | +The idea with incremental compilation is that you only need to compile the code you've actually |
| 57 | +changed, which means that that second build is faster. |
| 58 | + |
| 59 | +As of Rust 1.24, this is now [turned on by default](https://github.com/rust-lang/cargo/pull/4817). |
| 60 | +This means that your builds should get faster! Don't forget about `cargo check` when trying |
| 61 | +to get the lowest possible build times. |
| 62 | + |
| 63 | +This is still not the end story for compiler performance generally, nor incremental compilation |
| 64 | +specifically. We have a lot more work planned in the future. For example, another change |
| 65 | +related to performance hit stable this release: |
| 66 | +[`codegen-units` is now set to 16 by default](https://github.com/rust-lang/rust/pull/46910). |
| 67 | +One small note about this change: it makes builds faster, but makes the final binary a bit |
| 68 | +slower. For maximum speed, setting `codegen-units` to `1` in your `Cargot.toml` is needed |
| 69 | +to eake out every last drop of performance. |
| 70 | + |
| 71 | +More to come! |
| 72 | + |
| 73 | +#### Other good stuff |
| 74 | + |
| 75 | +There's one other change we'd like to talk about here: undefined behavior. Rust generally |
| 76 | +strives to minimize undefined behavior, having none of it in safe code, and as little as |
| 77 | +possible in unsafe code. One area where you could invoke UB is when a `panic!` goes |
| 78 | +across an FFI boundary. In other words, this: |
| 79 | + |
| 80 | +```rust |
| 81 | +extern "C" fn panic_in_ffi() { |
| 82 | + panic!("Test"); |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +This cannot work, as the exact mechanism of how panics work would have to be reconciled |
| 87 | +with how the `"C"` ABI works, in this example, or any other ABI in other examples. |
| 88 | + |
| 89 | +In Rust 1.24, [this code will now abort](https://github.com/rust-lang/rust/pull/46833) |
| 90 | +instead of producing undefined behavior. |
| 91 | + |
| 92 | +See the [detailed release notes][notes] for more. |
| 93 | + |
| 94 | +### Library stabilizations |
| 95 | + |
| 96 | +If you're a fan of `str::find`, which is used to find a given `char` inside of a `&str`, you'll be |
| 97 | +happy to see this pull request: [it's now 10x faster](https://github.com/rust-lang/rust/pull/46735)! |
| 98 | +This is thanks to `memchr`. `[u8]::contains` [uses it too](https://github.com/rust-lang/rust/pull/46713), |
| 99 | +though it doesn't get such an extreme speedup. |
| 100 | + |
| 101 | +Additionally, a few new APIs were stabilized this release: |
| 102 | + |
| 103 | +* [`RefCell::replace`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.replace) |
| 104 | +* [`RefCell::swap`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.swap) |
| 105 | +* [`std::sync::atomic::spin_loop_hint`](https://doc.rust-lang.org/std/sync/atomic/fn.spin_loop_hint.html) |
| 106 | + |
| 107 | +Finally, these functions may now be used inside a constant expression, for example, to initialize a `static`: |
| 108 | + |
| 109 | +* `Cell`, `RefCell`, and `UnsafeCell`'s `new` functions |
| 110 | +* The `new` functions of the various `Atomic` integer types |
| 111 | +* `{integer}::min_value` and `max_value` |
| 112 | +* `mem`'s `size_of` and `align_of` |
| 113 | +* `ptr::null` and `null_mut` |
| 114 | + |
| 115 | +See the [detailed release notes][notes] for more. |
| 116 | + |
| 117 | +### Cargo features |
| 118 | + |
| 119 | +The big feature of this release was turning on incremental compilation by default, as mentioned above. |
| 120 | + |
| 121 | +See the [detailed release notes][notes] for more. |
| 122 | + |
| 123 | +## Contributors to 1.24.0 |
| 124 | + |
| 125 | +Many people came together to create Rust 1.24. We couldn't have done it |
| 126 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.24.0) |
0 commit comments