Skip to content

Commit eba7d7c

Browse files
committed
Rust 1.20.0 release post
1 parent e11ca98 commit eba7d7c

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed

_posts/2017-08-31-Rust-1.20.md

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.20"
4+
author: The Rust Core Team
5+
---
6+
7+
The Rust team is happy to announce the latest version of Rust, 1.20.0. Rust
8+
is a fast, fearless, and friendly programming language.
9+
10+
If you have a previous version of Rust installed, getting Rust 1.20 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.20.0][notes] on GitHub. 1443 patches were landed in this release.
19+
20+
[install]: https://www.rust-lang.org/install.html
21+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1200-2017-08-31
22+
23+
### What's in 1.20.0 stable
24+
25+
In Rust, you can define traits, structs, and enums that have "associated functions":
26+
27+
```rust
28+
struct Struct;
29+
30+
impl Struct {
31+
fn foo() {
32+
println!("foo is an associated function of Struct");
33+
}
34+
}
35+
36+
fn main() {
37+
Struct::foo();
38+
}
39+
```
40+
41+
These are called "associated functions" becuase they are functions that are
42+
associated with the type, that is, they're attached to the type itself, and
43+
not any particular instance.
44+
45+
Rust 1.20 adds the ability to define "associated constants" as well:
46+
47+
```rust
48+
struct Struct;
49+
50+
impl Struct {
51+
const ID: u32 = 0;
52+
}
53+
54+
fn main() {
55+
println!("the ID of Struct is: {}", Struct::ID);
56+
}
57+
```
58+
59+
That is, the constant `ID` is associated with `Struct`. Like functions,
60+
associated constants work with traits and enums as well.
61+
62+
Traits have an extra ability with associated constants that gives them some
63+
extra power. With a trait, you can use an associated constant in the same way
64+
you'd use an associated type: by declaring it, but not giving it a value. The
65+
implementor of the trait then declares its value upon implementation:
66+
67+
```rust
68+
trait Trait {
69+
const ID: u32;
70+
}
71+
72+
struct Struct;
73+
74+
impl Trait for Struct {
75+
const ID: u32 = 5;
76+
}
77+
78+
fn main() {
79+
println!("{}", Struct::ID);
80+
}
81+
```
82+
83+
Before this release, if you wanted to make a trait that represented floating
84+
point numbers, you'd have to write this:
85+
86+
```rust
87+
trait Float {
88+
fn nan() -> Self;
89+
fn infinity() -> Self;
90+
...
91+
}
92+
```
93+
94+
This is slightly unweildy, but more importantly, becuase they're functions, they
95+
cannot be used in constant expressions, even though they only return a constant.
96+
Because of this, a design for `Float` would also have to include constants as well:
97+
98+
```rust
99+
mod f32 {
100+
const NAN: f32 = 0.0f32 / 0.0f32;
101+
const INFINITY: f32 = 1.0f32 / 0.0f32;
102+
103+
impl Float for f32 {
104+
fn nan() -> Self {
105+
f32::NAN
106+
}
107+
fn infinity() -> Self {
108+
f32::INFINITY
109+
}
110+
}
111+
}
112+
```
113+
114+
Associated constants let you do this in a much cleaner way. This trait definition:
115+
116+
```rust
117+
trait Float {
118+
const NAN: Self;
119+
const INFINITY: Self;
120+
...
121+
}
122+
```
123+
124+
Leads to this implementation:
125+
126+
```rust
127+
mod f32 {
128+
impl Float for f32 {
129+
const NAN: f32 = 0.0f32 / 0.0f32;
130+
const INFINITY: f32 = 1.0f32 / 0.0f32;
131+
}
132+
}
133+
```
134+
135+
much cleaner, and more versitile.
136+
137+
Associated constants were proposed in [RFC 195], almost exactly three years ago. It's
138+
been quite a while for this feature! That RFC contained all associated items, not just
139+
constants, and so some of them, such as associated types, were implemented faster than
140+
others. In general, we've been doing a lot of internal work for constant evaluation,
141+
to increase Rust's capabilities for compile-time metaprogramming. Expect more on this
142+
front in the future.
143+
144+
[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
145+
146+
Back in [Rust 1.14], we announced preliminary support for asm.js and wasm
147+
with the help of Emscripten. Since then, LLVM has added its own support, and
148+
so, we have [added native wasm support to Rust]! It's using the
149+
`wasm32-experimental-emscripten` target.
150+
151+
[Rust 1.14]: https://blog.rust-lang.org/2016/12/22/Rust-1.14.html
152+
[added native wasm support to Rust]: https://github.com/rust-lang/rust/pull/42571
153+
154+
See the [detailed release notes][notes] for more.
155+
156+
#### Library stabilizations
157+
158+
There's nothing *super* exciting in libraries this release, just a number of solid
159+
improvements and continued stabilizing of APIs.
160+
161+
The `unimplemented!` macro [now accepts
162+
messages](https://github.com/rust-lang/rust/pull/42155) that let you say why
163+
something is not yet implemented.
164+
165+
We [upgraded to Unicode 10.0.0](https://github.com/rust-lang/rust/pull/42999).
166+
167+
`min` and `max` on floating point types were [rewritten in
168+
Rust](https://github.com/rust-lang/rust/pull/42430), no longer relying on
169+
`cmath`.
170+
171+
We now [skip the main thread's manual stack guard on
172+
Linux](https://github.com/rust-lang/rust/pull/43072), due to mitigations in
173+
the kernel against [Stack
174+
Clash](https://access.redhat.com/security/vulnerabilities/stackguard).
175+
176+
The following APIs were also stabilized:
177+
178+
- [`CStr::into_c_string`]
179+
- [`CString::as_c_str`] and [`CString::into_boxed_c_str`]
180+
- [`Chain::get_mut`], [`Chain::get_ref`], and [`Chain::into_inner`]
181+
- [`Option::get_or_insert_with`] and [`Option::get_or_insert`]
182+
- [`OsStr::into_os_string`]
183+
- [`OsString::into_boxed_os_str`]
184+
- [`Take::get_mut`] and [`Take::get_ref`]
185+
- [`Utf8Error::error_len`]
186+
- [`char::EscapeDebug`] and [`char::escape_debug`]
187+
- [`compile_error!`]
188+
- [`f32::from_bits`] and [`f32::to_bits`]
189+
- [`f64::from_bits`] and [`f64::to_bits`]
190+
- [`mem::ManuallyDrop`]
191+
- [`slice::sort_unstable_by_key`], [`slice::sort_unstable_by`], and [`slice::sort_unstable`]
192+
- [`str::from_boxed_utf8_unchecked`]
193+
- [`str::as_bytes_mut`]
194+
- [`str::from_utf8_mut`] and [`str::from_utf8_unchecked_mut`]
195+
- [`str::get_unchecked`] and [`str::get_unchecked_mut`]
196+
- [`str::get`] and [`str::get_mut`]
197+
- [`str::into_boxed_bytes`]
198+
199+
[`CStr::into_c_string`]: https://doc.rust-lang.org/std/ffi/struct.CStr.html#method.into_c_string
200+
[`CString::as_c_str`]: https://doc.rust-lang.org/std/ffi/struct.CString.html#method.as_c_str
201+
[`CString::into_boxed_c_str`]: https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
202+
[`Chain::get_mut`]: https://doc.rust-lang.org/std/io/struct.Chain.html#method.get_mut
203+
[`Chain::get_ref`]: https://doc.rust-lang.org/std/io/struct.Chain.html#method.get_ref
204+
[`Chain::into_inner`]: https://doc.rust-lang.org/std/io/struct.Chain.html#method.into_inner
205+
[`Option::get_or_insert_with`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.get_or_insert_with
206+
[`Option::get_or_insert`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.get_or_insert
207+
[`OsStr::into_os_string`]: https://doc.rust-lang.org/std/ffi/struct.OsStr.html#method.into_os_string
208+
[`OsString::into_boxed_os_str`]: https://doc.rust-lang.org/std/ffi/struct.OsString.html#method.into_boxed_os_str
209+
[`Take::get_mut`]: https://doc.rust-lang.org/std/io/struct.Take.html#method.get_mut
210+
[`Take::get_ref`]: https://doc.rust-lang.org/std/io/struct.Take.html#method.get_ref
211+
[`Utf8Error::error_len`]: https://doc.rust-lang.org/std/str/struct.Utf8Error.html#method.error_len
212+
[`char::EscapeDebug`]: https://doc.rust-lang.org/std/char/struct.EscapeDebug.html
213+
[`char::escape_debug`]: https://doc.rust-lang.org/std/primitive.char.html#method.escape_debug
214+
[`compile_error!`]: https://doc.rust-lang.org/std/macro.compile_error.html
215+
[`f32::from_bits`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_bits
216+
[`f32::to_bits`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_bits
217+
[`f64::from_bits`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits
218+
[`f64::to_bits`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits
219+
[`mem::ManuallyDrop`]: https://doc.rust-lang.org/std/mem/union.ManuallyDrop.html
220+
[`slice::sort_unstable_by_key`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by_key
221+
[`slice::sort_unstable_by`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable_by
222+
[`slice::sort_unstable`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable
223+
[`str::from_boxed_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_boxed_utf8_unchecked.html
224+
[`str::as_bytes_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_bytes_mut
225+
[`str::from_utf8_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_mut.html
226+
[`str::from_utf8_unchecked_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked_mut.html
227+
[`str::get_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.get_mut
228+
[`str::get_unchecked_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.get_unchecked_mut
229+
[`str::get_unchecked`]: https://doc.rust-lang.org/std/primitive.str.html#method.get_unchecked
230+
[`str::get`]: https://doc.rust-lang.org/std/primitive.str.html#method.get
231+
[`str::into_boxed_bytes`]: https://doc.rust-lang.org/std/primitive.str.html#method.into_boxed_bytes
232+
233+
See the [detailed release notes][notes] for more.
234+
235+
#### Cargo features
236+
237+
Cargo has some nice upgrades this release. First of all, your crates.io
238+
authentication token used to be stored in `~/.cargo/config`. As a configuration
239+
file, this would often be stored with `644` permissions, that is, world-readable.
240+
But it has a secret token in it. We've [moved the token] `~/.cargo/credentials`,
241+
so that it can be permissioned `600`, and hidden from other users on your system.
242+
You'll get a warning if it's still in your `~/.cargo/config`.
243+
244+
[moved the token]: https://github.com/rust-lang/cargo/pull/3978
245+
246+
If you used secondary binaries in a Cargo package, you know that they're kept
247+
in `src/bin`. However, sometimes, you want multiple secondary binaries that
248+
have significant logic; in that case, you'd have `src/bin/client.rs` and
249+
`src/bin/server.rs`, and any submodules for either of them would go in the
250+
same directory. This is confusing. Instead, [we now conventionally support]
251+
`src/bin/client/main.rs` and `src/bin/server/main.rs`, so that you can keep
252+
larger binaries more separate from one another.
253+
254+
[we now conventionally support]: https://github.com/rust-lang/cargo/pull/4214
255+
256+
See the [detailed release notes][notes] for more.
257+
258+
### Contributors to 1.20.0
259+
260+
Many people came together to create Rust 1.20. We couldn't have done it without
261+
all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.20.0)

0 commit comments

Comments
 (0)