Skip to content

Commit 98f0d63

Browse files
committed
Rust 1.19
1 parent 1bfacf1 commit 98f0d63

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed

_posts/2017-07-20-Rust-1.19.md

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

0 commit comments

Comments
 (0)