|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.19" |
| 4 | +author: The Rust Core Team |
| 5 | +--- |
| 6 | + |
| 7 | +The Rust team is happy to announce the latest version of Rust, 1.19.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, getting Rust 1.19 is as easy as: |
| 11 | + |
| 12 | +```bash |
| 13 | +$ rustup update stable |
| 14 | +``` |
| 15 | + |
| 16 | +If you don't have it already, you can [get `rustup`][install] from the |
| 17 | +appropriate page on our website, and check out the [detailed release notes for |
| 18 | +1.19.0][notes] on GitHub. |
| 19 | + |
| 20 | +[install]: https://www.rust-lang.org/install.html |
| 21 | +[notes]: https://github.com/rust-lang/rust/blob/rust-1.19.0-relnotes/RELEASES.md#version-1190-2017-07-20 |
| 22 | + |
| 23 | +### What's in 1.19.0 stable |
| 24 | + |
| 25 | +Rust 1.19.0 has some long-awaited features, but first, a note for our Windows |
| 26 | +users. On Windows, Rust relies on `link.exe` for linking, which you can get via |
| 27 | +the "Microsoft Visual C++ Build Tools." With the recent release of Visual |
| 28 | +Studio 2017, the directory structure for these tools has changed. As such, to |
| 29 | +use Rust, you had to stick with the 2015 tools or use a workaround (such as |
| 30 | +running `vcvars.bat`). In 1.19.0, `rustc` now knows how to find the 2017 tools, |
| 31 | +and so they work without a workaround. |
| 32 | + |
| 33 | +On to new features! Rust 1.19.0 is the first release that supports [`union`s]: |
| 34 | + |
| 35 | +```rust |
| 36 | +union MyUnion { |
| 37 | + f1: u32, |
| 38 | + f2: f32, |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +Unions are kind of like `enum`s, but they are "untagged". Enums have a "tag" |
| 43 | +that stores which variant is the correct one at runtime; unions elide this tag. |
| 44 | + |
| 45 | +Since we can interpret the data held in the union using the wrong variant and |
| 46 | +Rust can't check this for us, that means reading or writing a union's field is |
| 47 | +unsafe: |
| 48 | + |
| 49 | +```rust |
| 50 | +let u = MyUnion { f1: 1 }; |
| 51 | + |
| 52 | +unsafe { u.f1 = 5 }; |
| 53 | + |
| 54 | +let value = unsafe { u.f1 }; |
| 55 | +``` |
| 56 | + |
| 57 | +Pattern matching works too: |
| 58 | + |
| 59 | +```rust |
| 60 | +fn f(u: MyUnion) { |
| 61 | + unsafe { |
| 62 | + match u { |
| 63 | + MyUnion { f1: 10 } => { println!("ten"); } |
| 64 | + MyUnion { f2 } => { println!("{}", f2); } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +When are unions useful? One major use-case is interoperability with C. C APIs |
| 71 | +can (and depending on the area, often do) expose unions, and so this makes writing |
| 72 | +API wrappers for those libraries significantly easier. Additionally, from [its RFC]: |
| 73 | + |
| 74 | +> A native union mechanism would also simplify Rust implementations of |
| 75 | +> space-efficient or cache-efficient structures relying on value |
| 76 | +> representation, such as machine-word-sized unions using the least-significant |
| 77 | +> bits of aligned pointers to distinguish cases. |
| 78 | +
|
| 79 | +This feature has been long awaited, and there's still more improvements to come. |
| 80 | +For now, `union`s can only include `Copy` types and may not implement `Drop`. |
| 81 | +We expect to lift these restrictions in the future. |
| 82 | + |
| 83 | +[`union`s]: https://github.com/rust-lang/rust/pull/42068 |
| 84 | +[its RFC]: https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md#motivation |
| 85 | + |
| 86 | +> As a side note, have you ever wondered how new features get added to Rust? This |
| 87 | +> feature was suggested by Josh Triplet, and he [gave a talk at RustConf |
| 88 | +> 2016](https://youtu.be/U8Gl3RTXf88?list=PLE7tQUdRKcybLShxegjn0xyTTDJeYwEkI) |
| 89 | +> about the process of getting `union`s into Rust. You should check it out! |
| 90 | +
|
| 91 | +In other news, [`loop`s can now `break` with a value](https://github.com/rust-lang/rust/pull/42016): |
| 92 | + |
| 93 | +```rust |
| 94 | +// old code |
| 95 | +let x; |
| 96 | + |
| 97 | +loop { |
| 98 | + x = 7; |
| 99 | + break; |
| 100 | +} |
| 101 | + |
| 102 | +// new code |
| 103 | +let x = loop { break 7; }; |
| 104 | +``` |
| 105 | + |
| 106 | +Rust has traditionally positioned itself as an "expression oriented language", that is, |
| 107 | +most things are expressions that evaluate to a value, rather than statements. `loop` stuck |
| 108 | +out as strange in this way, as it was previously a statement. |
| 109 | + |
| 110 | +What about other forms of loops? It's not yet clear. See [its |
| 111 | +RFC](https://github.com/rust-lang/rfcs/blob/master/text/1624-loop-break-value.md#extension-to-for-while-while-let) |
| 112 | +for some discussion around the open questions here. |
| 113 | + |
| 114 | +A smaller feature, closures that do not capture an environment [can now be coerced |
| 115 | +to a function pointer](https://github.com/rust-lang/rust/pull/42162): |
| 116 | + |
| 117 | +```rust |
| 118 | +let f: fn(i32) -> i32 = |x| x + 1; |
| 119 | +``` |
| 120 | + |
| 121 | +We now produce [xz compressed tarballs](https://github.com/rust-lang/rust-installer/pull/57) and prefer them by default, |
| 122 | +making the data transfer smaller and faster. `gzip`'d tarballs are still produced |
| 123 | +in case you can't use `xz` for some reason. |
| 124 | + |
| 125 | +The compiler can now [bootstrap on |
| 126 | +Android](https://github.com/rust-lang/rust/pull/41370). We've long supported Android |
| 127 | +in various ways, and this continues to improve our support. |
| 128 | + |
| 129 | +Finally, a compatibility note. Way back when we were running up to Rust 1.0, we did |
| 130 | +a huge push to verify everything that was being marked as stable and as unstable. |
| 131 | +We overlooked one thing, however: `-Z` flags. The `-Z` flag to the compiler enables |
| 132 | +unstable flags. Unlike the rest of our stability story, you could still use `-Z` on |
| 133 | +stable Rust. Back in April of 2016, in Rust 1.8, we made the use of `-Z` on stable |
| 134 | +or beta produce a warning. Over a year later, we're fixing this hole in our |
| 135 | +stability story by [disallowing `-Z` on stable and beta](https://github.com/rust-lang/rust/pull/41751). |
| 136 | + |
| 137 | +See the [detailed release notes][notes] for more. |
| 138 | + |
| 139 | +#### Library stabilizations |
| 140 | + |
| 141 | +The largest new library feature is the [`eprint!` and `eprintln!` macros]. |
| 142 | +These work exactly the same as `print!` and `printn!` but instead write |
| 143 | +to standard error, as opposed to standard output. |
| 144 | + |
| 145 | +[`eprint!` and `eprintln!` macros]: https://github.com/rust-lang/rust/pull/41192 |
| 146 | + |
| 147 | +Other new features: |
| 148 | + |
| 149 | +- [`String` now implements `FromIterator<Cow<'a, str>>` and |
| 150 | + `Extend<Cow<'a, str>>`][41449] |
| 151 | +- [`Vec` now implements `From<&mut [T]>`][41530] |
| 152 | +- [`Box<[u8]>` now implements `From<Box<str>>`][41258] |
| 153 | +- [`SplitWhitespace` now implements `Clone`][41659] |
| 154 | +- [`[u8]::reverse` is now 5x faster and `[u16]::reverse` is now |
| 155 | + 1.5x faster][41764] |
| 156 | + |
| 157 | +[41449]: https://github.com/rust-lang/rust/pull/41449 |
| 158 | +[41530]: https://github.com/rust-lang/rust/pull/41530 |
| 159 | +[41258]: https://github.com/rust-lang/rust/pull/41258 |
| 160 | +[41659]: https://github.com/rust-lang/rust/pull/41659 |
| 161 | +[41764]: https://github.com/rust-lang/rust/pull/41764 |
| 162 | + |
| 163 | +And some freshly-stabilized APIs: |
| 164 | + |
| 165 | +- [`OsString::shrink_to_fit`] |
| 166 | +- [`cmp::Reverse`] |
| 167 | +- [`Command::envs`] |
| 168 | +- [`thread::ThreadId`] |
| 169 | + |
| 170 | +[`OsString::shrink_to_fit`]: https://doc.rust-lang.org/std/ffi/struct.OsString.html#method.shrink_to_fit |
| 171 | +[`cmp::Reverse`]: https://doc.rust-lang.org/std/cmp/struct.Reverse.html |
| 172 | +[`Command::envs`]: https://doc.rust-lang.org/std/process/struct.Command.html#method.envs |
| 173 | +[`thread::ThreadId`]: https://doc.rust-lang.org/std/thread/struct.ThreadId.html |
| 174 | + |
| 175 | +See the [detailed release notes][notes] for more. |
| 176 | + |
| 177 | +#### Cargo features |
| 178 | + |
| 179 | +Cargo mostly received small but valuable improvements in this release. The |
| 180 | +largest is possibly that [Cargo no longer checks out a local working |
| 181 | +directory for the crates.io index][cargo/4026]. This should provide smaller |
| 182 | +file size for the registry and improve cloning times, especially on Windows |
| 183 | +machines. |
| 184 | + |
| 185 | +Other improvements: |
| 186 | + |
| 187 | +- [Build scripts can now add environment variables to the environment |
| 188 | + the crate is being compiled in. |
| 189 | + Example: `println!("cargo:rustc-env=FOO=bar");`][cargo/3929] |
| 190 | +- [Workspace members can now accept glob file patterns][cargo/3979] |
| 191 | +- [Added `--all` flag to the `cargo bench` subcommand to run benchmarks of all |
| 192 | + the members in a given workspace.][cargo/3988] |
| 193 | +- [Added an `--exclude` option for excluding certain packages when using the |
| 194 | + `--all` option][cargo/4031] |
| 195 | +- [The `--features` option now accepts multiple comma or space |
| 196 | + delimited values.][cargo/4084] |
| 197 | +- [Added support for custom target specific runners][cargo/3954] |
| 198 | + |
| 199 | +[cargo/3929]: https://github.com/rust-lang/cargo/pull/3929 |
| 200 | +[cargo/3954]: https://github.com/rust-lang/cargo/pull/3954 |
| 201 | +[cargo/3979]: https://github.com/rust-lang/cargo/pull/3979 |
| 202 | +[cargo/3988]: https://github.com/rust-lang/cargo/pull/3988 |
| 203 | +[cargo/4026]: https://github.com/rust-lang/cargo/pull/4026 |
| 204 | +[cargo/4031]: https://github.com/rust-lang/cargo/pull/4031 |
| 205 | +[cargo/4084]: https://github.com/rust-lang/cargo/pull/4084 |
| 206 | + |
| 207 | +See the [detailed release notes][notes] for more. |
| 208 | + |
| 209 | +### Contributors to 1.19.0 |
| 210 | + |
| 211 | +Many people came together to create Rust 1.19. We couldn't have done it without |
| 212 | +all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.19.0) |
0 commit comments