|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.25" |
| 4 | +author: The Rust Core Team |
| 5 | +--- |
| 6 | + |
| 7 | +The Rust team is happy to announce a new version of Rust, 1.25.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.25.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.25.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-1250-2018-03-29 |
| 23 | + |
| 24 | +## What's in 1.25.0 stable |
| 25 | + |
| 26 | +The last few releases have been relatively minor, but Rust 1.25 contains a |
| 27 | +bunch of stuff! The first one is straightforward: we've [upgraded to LLVM 6] |
| 28 | +from LLVM 4. This has a number of effects, a major one |
| 29 | +being a step closer to AVR support. |
| 30 | + |
| 31 | +A new way to write `use` statements has landed: [nested import groups]. If you've |
| 32 | +ever written a set of imports like this: |
| 33 | + |
| 34 | +```rust |
| 35 | +use std::fs::File; |
| 36 | +use std::io::Read; |
| 37 | +use std::path::{Path, PathBuf}; |
| 38 | +``` |
| 39 | + |
| 40 | +You can now write this: |
| 41 | + |
| 42 | +```rust |
| 43 | +// on one line |
| 44 | +use std::{fs::File, io::Read, path::{Path, PathBuf}}; |
| 45 | + |
| 46 | +// with some more breathing room |
| 47 | +use std::{ |
| 48 | + fs::File, |
| 49 | + io::Read, |
| 50 | + path::{ |
| 51 | + Path, |
| 52 | + PathBuf |
| 53 | + } |
| 54 | +}; |
| 55 | +``` |
| 56 | + |
| 57 | +This can reduce some repetition, and make things a bit more clear. |
| 58 | + |
| 59 | +There are two big documentation changes in this release: first, [Rust By |
| 60 | +Example is now included on doc.rust-lang.org]! We'll be redirecting the old |
| 61 | +domain there shortly. We hope this will bring more attention to a great |
| 62 | +resource, and you'll get a local copy with your local documentation. |
| 63 | + |
| 64 | +Second, back in Rust 1.23, we talked about the change from Hoedown to |
| 65 | +pulldown-cmark. In Rust 1.25, pulldown-cmark is now the default. We have |
| 66 | +finally removed the last bit of C from rustdoc, and now properly follow the |
| 67 | +CommonMark spec. |
| 68 | + |
| 69 | +Finally, in [RFC 1358], `#[repr(align(x))]` was accepted. In Rust |
| 70 | +1.25, [it is now stable]! This attribute lets you set the [alignment] |
| 71 | +of your `struct`s: |
| 72 | + |
| 73 | +```rust |
| 74 | +struct Number(i32); |
| 75 | + |
| 76 | +assert_eq!(std::mem::align_of::<Number>(), 4); |
| 77 | +assert_eq!(std::mem::size_of::<Number>(), 4); |
| 78 | + |
| 79 | +#[repr(align(16))] |
| 80 | +struct Align16(i32); |
| 81 | + |
| 82 | +assert_eq!(std::mem::align_of::<Align16>(), 16); |
| 83 | +assert_eq!(std::mem::size_of::<Align16>(), 16); |
| 84 | +``` |
| 85 | + |
| 86 | +If you're working with low-level stuff, control of these kinds of things |
| 87 | +can be very important! |
| 88 | + |
| 89 | +[upgraded to LLVM 6]: https://github.com/rust-lang/rust/pull/47828 |
| 90 | +[nested import groups]: https://github.com/rust-lang/rust/pull/47948 |
| 91 | +[Rust By Example is now included on doc.rust-lang.org]: https://doc.rust-lang.org/rust-by-example/ |
| 92 | +[RFC 1358]: https://github.com/rust-lang/rfcs/blob/master/text/1358-repr-align.md |
| 93 | +[it is now stable]: https://github.com/rust-lang/rust/pull/47006 |
| 94 | +[alignment]: https://en.wikipedia.org/wiki/Data_structure_alignment |
| 95 | + |
| 96 | +See the [detailed release notes][notes] for more. |
| 97 | + |
| 98 | +### Library stabilizations |
| 99 | + |
| 100 | +The biggest story in libraries this release is [`std::ptr::NonNull<T>`]. This type |
| 101 | +is similar to `*mut T`, but is non-null and covariant. This blog post isn't the right |
| 102 | +place to explain variance, but in a nutshell, `NonNull<T>`, well, guarantees that it |
| 103 | +won't be null, which means that `Option<NonNull<T>>` is the same size as `Option<T>`. |
| 104 | +If you're building a data structure with unsafe code, `NonNull<T>` is often the right |
| 105 | +type for you! |
| 106 | + |
| 107 | +[`std::ptr::NonNull<T>`]: https://doc.rust-lang.org/std/ptr/struct.NonNull.html |
| 108 | + |
| 109 | +`libcore` has [gained a `time` module](https://doc.rust-lang.org/core/time/), |
| 110 | +containing the `Duration` type previously only available in `libstd`. |
| 111 | + |
| 112 | +Additionally, the `from_secs`, and `from_milis` functions associated with |
| 113 | +`Duration` were made `const fn`s, allowing them to be used to create a |
| 114 | +`Duration` as a constant expression. |
| 115 | + |
| 116 | +See the [detailed release notes][notes] for more. |
| 117 | + |
| 118 | +### Cargo features |
| 119 | + |
| 120 | +Cargo's CLI has one really important change this release: `cargo new` will |
| 121 | +[now default](https://github.com/rust-lang/cargo/pull/5029) to generating a |
| 122 | +binary, rather than a library. We try to keep Cargo's CLI quite stable, but |
| 123 | +this change is important, and is unlikely to cause breakage. |
| 124 | + |
| 125 | +For some background, `cargo new` accepts two flags: `--lib`, for creating libraries, |
| 126 | +and `--bin`, for creating binaries, or executables. If you don't pass one of these |
| 127 | +flags, in previous versions of Cargo, it would default to `--lib`. We made this |
| 128 | +decision because each binary (often) depends on many libraries, and so the library |
| 129 | +case is more common. However, this is incorrect; each library is *depended upon* by |
| 130 | +many binaries. Furthermore, when getting stated, what you often want is a program |
| 131 | +you can run and play around with. It's not just new Rustaceans though; even very |
| 132 | +long-time community members have said that they find this default surprising. |
| 133 | +As such, we're changing it. |
| 134 | + |
| 135 | +Similarly, `cargo new` previously would be a bit opinionated around the names |
| 136 | +of packages it would create. Specifically, if your package began with `rust-` |
| 137 | +or ended with `-rs`, Cargo would rename it. The intention was that well, |
| 138 | +it's a Rust package, this information is redundant. However, people feel |
| 139 | +quite strongly about naming, and when they bump into this, they're surprised |
| 140 | +and often upset. As such, [we're not going to do that any |
| 141 | +more](https://github.com/rust-lang/cargo/pull/5013). |
| 142 | + |
| 143 | +Many users love `cargo doc`, a way to generate local documentation for their |
| 144 | +Cargo projects. [It's getting a huge speed |
| 145 | +bump](https://github.com/rust-lang/cargo/pull/4976) in this release, as now, |
| 146 | +it uses `cargo check`, rather than a full `cargo build`, so some scenarios |
| 147 | +will get faster. |
| 148 | + |
| 149 | +Additionally, checkouts of git dependencies [should be a lot |
| 150 | +faster](https://github.com/rust-lang/cargo/pull/4919), thanks to the use of |
| 151 | +hard links when possible. |
| 152 | + |
| 153 | +See the [detailed release notes][notes] for more. |
| 154 | + |
| 155 | +## Contributors to 1.25.0 |
| 156 | + |
| 157 | +Many people came together to create Rust 1.25. We couldn't have done it |
| 158 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.25.0) |
0 commit comments