-
Notifications
You must be signed in to change notification settings - Fork 307
release blog post for Rust 1.46.0 #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5019fca
1ff5091
0e1247c
9da698e
da36ac2
86a6712
f54f844
bfd17f5
1b6d03e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
layout: post | ||
title: "Announcing Rust 1.46.0" | ||
author: The Rust Release Team | ||
release: true | ||
--- | ||
|
||
The Rust team is happy to announce a new version of Rust, 1.46.0. Rust is a | ||
programming language that is empowering everyone to build reliable and | ||
efficient software. | ||
|
||
If you have a previous version of Rust installed via rustup, getting Rust | ||
1.46.0 is as easy as: | ||
|
||
```console | ||
rustup update stable | ||
``` | ||
|
||
If you don't have it already, you can [get `rustup`][install] from the | ||
appropriate page on our website, and check out the [detailed release notes for | ||
1.46.0][notes] on GitHub. | ||
|
||
[install]: https://www.rust-lang.org/install.html | ||
[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1460-2020-08-27 | ||
|
||
## What's in 1.46.0 stable | ||
|
||
This release is on the smaller side, with a number of improvements to `const | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn`, two new standard library APIs, and one feature useful for library | ||
authors. See the [detailed release notes][notes] to learn about other changes | ||
not covered by this post. | ||
|
||
### `#[track_caller]` | ||
|
||
Back in March, the release of Rust 1.42 brought about [better error messages when unwrap would panic][better-errors]. At the time, we mentioned that the way | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this was implemented was not yet stable. Rust 1.46 stabilizes this feature. | ||
|
||
[better-errors]: https://blog.rust-lang.org/2020/03/12/Rust-1.42.html#useful-line-numbers-in-option-and-result-panic-messages | ||
|
||
This attribute is called `#[track_caller]`, which was originally proposed | ||
in [RFC 2091][rfc-2091] way back in July of 2017! If you're writing a function | ||
like unwrap, where you want errors to report to the caller, you can put this | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
annotation on your functions, and the default panic formatter will use it to | ||
print its error message. For example, here is `unwrap` previously: | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```rust | ||
pub fn unwrap(self) -> T { | ||
match self { | ||
Some(val) => val, | ||
None => panic!("called `Option::unwrap()` on a `None` value"), | ||
} | ||
} | ||
``` | ||
|
||
It now looks like this: | ||
|
||
```rust | ||
#[track_caller] | ||
pub fn unwrap(self) -> T { | ||
match self { | ||
Some(val) => val, | ||
None => panic!("called `Option::unwrap()` on a `None` value"), | ||
} | ||
} | ||
``` | ||
|
||
That's it! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think we should also reiterate how this changes the output? or is that too much? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should show only the changed output, rather than the code sample. There doesn't appear to be anything different about how this annotation is applied compared to existing annotations, so having a multi-line code diff seems mostly just confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...though an example that uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to emphasize how simple this is to use, but if you wanted to come up with an example using Location, I'm not inherently opposed. I didn't show how the output was changed because we did that when it was added to unwrap. |
||
|
||
If you are implementing a panic hook yourself, you can use the [caller] method | ||
on `std::panic::Location` to get access to this information. | ||
|
||
[rfc-2091]: https://github.com/rust-lang/rfcs/pull/2091 | ||
[caller]: https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.caller | ||
|
||
### `const fn` improvements | ||
|
||
You can now use [a variety of things] in a `const fn`: | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* `if` | ||
* `match` | ||
* the `&&` and `||` operators | ||
* `loop` | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can also [cast to a slice][cast-to-slice]: | ||
|
||
```rust | ||
const fn foo() { | ||
let x = [1, 2, 3, 4, 5]; | ||
|
||
// cast the array to a slice | ||
let y: &[_] = &x; | ||
} | ||
``` | ||
|
||
[a variety of things]: https://github.com/rust-lang/rust/pull/72437/ | ||
steveklabnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[cast-to-slice]: https://github.com/rust-lang/rust/pull/73862/ | ||
|
||
### Library changes | ||
|
||
Keeping with the theme of `const fn` improvements, [`std::mem::forget` is now | ||
a `const fn`][forget]. Additionally, two new APIs were stabilized this release: | ||
|
||
* [`Option::zip`][zip] | ||
* [`vec::Drain::as_slice`][as_slice] | ||
|
||
[forget]: https://github.com/rust-lang/rust/pull/73887/ | ||
[zip]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.zip | ||
[as_slice]: https://doc.rust-lang.org/stable/std/vec/struct.Drain.html#method.as_slice | ||
|
||
See the [detailed release notes][notes] for more. | ||
|
||
### Other changes | ||
|
||
[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-146-2020-08-27 | ||
[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-146 | ||
|
||
There are other changes in the Rust 1.46.0 release: check out what changed in | ||
[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy]. | ||
|
||
## Contributors to 1.46.0 | ||
|
||
Many people came together to create Rust 1.46.0. We couldn't have done it | ||
without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.46.0/) |
Uh oh!
There was an error while loading. Please reload this page.