Skip to content

Commit 8dcda32

Browse files
authored
Merge pull request #728 from steveklabnik/rust-1.48
Rust 1.48 release post
2 parents 813b00d + 9f5b906 commit 8dcda32

File tree

1 file changed

+232
-0
lines changed

1 file changed

+232
-0
lines changed

posts/2020-11-19-Rust-1.48.md

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
---
2+
layout: post
3+
title: "Announcing Rust 1.48.0"
4+
author: The Rust Release Team
5+
release: true
6+
---
7+
8+
The Rust team is happy to announce a new version of Rust, 1.48.0. Rust is a
9+
programming language that is empowering everyone to build reliable and
10+
efficient software.
11+
12+
If you have a previous version of Rust installed via rustup, getting Rust
13+
1.48.0 is as easy as:
14+
15+
```console
16+
rustup update stable
17+
```
18+
19+
If you don't have it already, you can [get `rustup`][install] from the
20+
appropriate page on our website, and check out the [detailed release notes for
21+
1.48.0][notes] on GitHub.
22+
23+
[install]: https://www.rust-lang.org/tools/install
24+
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1480-2020-11-19
25+
26+
## What's in 1.48.0 stable
27+
28+
The star of this release is Rustdoc, with a few changes to make writing
29+
documentation even easier! See the [detailed release notes][notes] to learn
30+
about other changes not covered by this post.
31+
32+
### Easier linking in rustdoc
33+
34+
Rustdoc, the library documentation tool included in the Rust distribution,
35+
lets you write documentation in Markdown. This makes it very easy to use, but
36+
also has some pain points. Let's say that you are writing some documentation
37+
for some Rust code that looks like this:
38+
39+
```rust
40+
pub mod foo {
41+
pub struct Foo;
42+
}
43+
44+
pub mod bar {
45+
pub struct Bar;
46+
}
47+
```
48+
49+
We have two modules, each with a struct inside. Imagine we wanted to use these
50+
two structs together; we may want to note this in the documentation. So we'd
51+
write some docs that look like this:
52+
53+
```rust
54+
pub mod foo {
55+
/// Some docs for `Foo`
56+
///
57+
/// You may want to use `Foo` with `Bar`.
58+
pub struct Foo;
59+
}
60+
61+
pub mod bar {
62+
/// Some docs for `Bar`
63+
///
64+
/// You may want to use `Bar` with `Foo`.
65+
pub struct Bar;
66+
}
67+
```
68+
69+
That's all well and good, but it would be really nice if we could link to these
70+
other types. That would make it much easier for the users of our library to
71+
navigate between them in our docs.
72+
73+
The problem here is that Markdown doesn't know anything about Rust, and the
74+
URLs that rustdoc generates. So what Rust programmers have had to do is write
75+
those links out manually:
76+
77+
```rust
78+
pub mod foo {
79+
/// Some docs for `Foo`
80+
///
81+
/// You may want to use `Foo` with [`Bar`].
82+
///
83+
/// [`Bar`]: ../bar/struct.Bar.html
84+
pub struct Foo;
85+
}
86+
87+
pub mod bar {
88+
/// Some docs for `Bar`
89+
///
90+
/// You may want to use `Bar` with [`Foo`].
91+
///
92+
/// [`Foo`]: ../foo/struct.Foo.html
93+
pub struct Bar;
94+
}
95+
```
96+
97+
Note that we've also had to use relative links, so that this works offline.
98+
Not only is this process tedious, and error prone, but it's also just wrong
99+
in places. If we put a `pub use bar::Bar` in our crate root, that would
100+
re-export `Bar` in our root. Now our links are wrong. But if we fix them,
101+
then they end up being wrong when we navigate to the `Bar` that lives inside
102+
the module. You can't actually write these links by hand, and have them all
103+
be accurate.
104+
105+
In this release, you can use some syntax to let rustdoc know that you're
106+
trying to link to a type, and it will generate the URLs for you. Here's
107+
two different examples, based off of our code before:
108+
109+
```rust
110+
pub mod foo {
111+
/// Some docs for `Foo`
112+
///
113+
/// You may want to use `Foo` with [`Bar`](crate::bar::Bar).
114+
pub struct Foo;
115+
}
116+
117+
pub mod bar {
118+
/// Some docs for `Bar`
119+
///
120+
/// You may want to use `Bar` with [`crate::foo::Foo`].
121+
pub struct Bar;
122+
}
123+
```
124+
125+
The first example will show the same text as before; but generate the proper
126+
link to the `Bar` type. The second will link to `Foo`, but will show the whole
127+
`crate::foo::Foo` as the link text.
128+
129+
There are a bunch of options you can use here. Please see the ["Linking to
130+
items by name"][intra-docs] section of the rustdoc book for more. There is also
131+
a post on Inside Rust [on the history of this feature][intra-history], written
132+
by some of the contributors behind it!
133+
134+
[intra-docs]: https://doc.rust-lang.org/stable/rustdoc/linking-to-items-by-name.html
135+
[intra-history]: https://blog.rust-lang.org/inside-rust/2020/09/17/stabilizing-intra-doc-links.html
136+
137+
### Adding search aliases
138+
139+
[You can now specify `#[doc(alias = "<alias>")]` on items to add search
140+
aliases when searching through `rustdoc`'s UI.][75740] This is a smaller change,
141+
but still useful. It looks like this:
142+
143+
```rust
144+
#[doc(alias = "bar")]
145+
struct Foo;
146+
```
147+
148+
With this annotation, if we search for "bar" in rustdoc's search, `Foo` will
149+
come up as part of the results, even though our search text doesn't have
150+
"Foo" in it.
151+
152+
An interesting use case for aliases is FFI wrapper crates, where each Rust
153+
function could be aliased to the C function it wraps. Existing users of the
154+
underlying C library would then be able to easily search the right Rust
155+
functions!
156+
157+
[75740]: https://github.com/rust-lang/rust/pull/75740/
158+
159+
### Library changes
160+
161+
The most significant API change is kind of a mouthful: `[T; N]: TryFrom<Vec<T>>`
162+
is now stable. What does this mean? Well, you can use this to try and turn
163+
a vector into an array of a given length:
164+
165+
```rust
166+
use std::convert::TryInto;
167+
168+
let v1: Vec<u32> = vec![1, 2, 3];
169+
170+
// This will succeed; our vector has a length of three, we're trying to
171+
// make an array of length three.
172+
let a1: [u32; 3] = v1.try_into().expect("wrong length");
173+
174+
// But if we try to do it with a vector of length five...
175+
let v2: Vec<u32> = vec![1, 2, 3, 4, 5];
176+
177+
// ... this will panic, since we have the wrong length.
178+
let a2: [u32; 3] = v2.try_into().expect("wrong length");
179+
```
180+
181+
In the last release, we talked about the standard library being able to use
182+
const generics. This is a good example of the kinds of APIs that we can add
183+
with these sorts of features. Expect to hear more about the stabilization of
184+
const generics soon.
185+
186+
Additionally, five new APIs were stabilized this release:
187+
188+
- [`slice::as_ptr_range`]
189+
- [`slice::as_mut_ptr_range`]
190+
- [`VecDeque::make_contiguous`]
191+
- [`future::pending`]
192+
- [`future::ready`]
193+
194+
The following previously stable APIs have now been made `const`:
195+
196+
- [`Option::is_some`]
197+
- [`Option::is_none`]
198+
- [`Option::as_ref`]
199+
- [`Result::is_ok`]
200+
- [`Result::is_err`]
201+
- [`Result::as_ref`]
202+
- [`Ordering::reverse`]
203+
- [`Ordering::then`]
204+
205+
See the [detailed release notes][notes] for more.
206+
207+
[`Option::is_some`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some
208+
[`Option::is_none`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.is_none
209+
[`Option::as_ref`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_ref
210+
[`Result::is_ok`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok
211+
[`Result::is_err`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err
212+
[`Result::as_ref`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.as_ref
213+
[`Ordering::reverse`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.reverse
214+
[`Ordering::then`]: https://doc.rust-lang.org/std/cmp/enum.Ordering.html#method.then
215+
[`slice::as_ptr_range`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_ptr_range
216+
[`slice::as_mut_ptr_range`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_mut_ptr_range
217+
[`VecDeque::make_contiguous`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.make_contiguous
218+
[`future::pending`]: https://doc.rust-lang.org/std/future/fn.pending.html
219+
[`future::ready`]: https://doc.rust-lang.org/std/future/fn.ready.html
220+
221+
### Other changes
222+
223+
[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-148-2020-11-19
224+
[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-148
225+
226+
There are other changes in the Rust 1.48.0 release: check out what changed in
227+
[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy].
228+
229+
## Contributors to 1.48.0
230+
231+
Many people came together to create Rust 1.48.0. We couldn't have done it
232+
without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.48.0/)

0 commit comments

Comments
 (0)