|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.57.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.57.0. |
| 9 | +Rust is a programming language empowering everyone to build reliable and efficient software. |
| 10 | + |
| 11 | +If you have a previous version of Rust installed via rustup, getting Rust 1.57.0 is as easy as: |
| 12 | + |
| 13 | +```console |
| 14 | +rustup update stable |
| 15 | +``` |
| 16 | + |
| 17 | +If you don't have it already, you can [get `rustup`][install] |
| 18 | +from the appropriate page on our website, and check out the |
| 19 | +[detailed release notes for 1.57.0][notes] on GitHub. |
| 20 | + |
| 21 | +[install]: https://www.rust-lang.org/install.html |
| 22 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1570-2021-12-02 |
| 23 | + |
| 24 | +## What's in 1.57.0 stable |
| 25 | + |
| 26 | +Rust 1.57 brings `panic!` to const contexts, adds support for custom profiles to Cargo, and stabilizes fallible reservation APIs. |
| 27 | + |
| 28 | +### `panic!` in const contexts |
| 29 | + |
| 30 | +With previous versions of Rust, the `panic!` macro was not usable in `const fn` and other compile-time contexts. Now, this has been stabilized. Together with the stabilization of `panic!`, several other standard library APIs are now usable in const, such as `assert!`. |
| 31 | + |
| 32 | +This stabilization does not yet include the full formatting infrastructure, so the `panic!` macro must be called with either a static string (`panic!("...")`), or with a single `&str` interpolated value (`panic!("{}", a)`) which must be used with `{}` (no format specifiers or other traits). |
| 33 | + |
| 34 | +It is expected that in the future this support will expand, but this minimal stabilization already enables straightforward compile-time assertions, for example to verify the size of a type: |
| 35 | + |
| 36 | +```rust |
| 37 | +const _: () = assert!(std::mem::size_of::<u64>() == 8); |
| 38 | +const _: () = assert!(std::mem::size_of::<u8>() == 1); |
| 39 | +``` |
| 40 | + |
| 41 | +### Cargo support for custom profiles |
| 42 | + |
| 43 | +Cargo has long supported four profiles: `dev`, `release`, `test`, and `bench`. With Rust 1.57, support has been added for arbitrarily named profiles. |
| 44 | + |
| 45 | +For example, if you want to enable link time optimizations ([LTO]) only when making the final production build, adding the following snippet to Cargo.toml enables the `lto` flag when this profile is selected, but avoids enabling it for regular release builds. |
| 46 | + |
| 47 | +```toml |
| 48 | +[profile.production] |
| 49 | +inherits = "release" |
| 50 | +lto = true |
| 51 | +``` |
| 52 | + |
| 53 | +Note that custom profiles must specify a profile from which they inherit default settings. Once the profile has been defined, Cargo commands which build code can be asked to use it with `--profile production`. Currently, this will build artifacts in a separate directory (`target/production` in this case), which means that artifacts are not shared between directories. |
| 54 | + |
| 55 | +[LTO]: https://doc.rust-lang.org/nightly/cargo/reference/profiles.html#lto |
| 56 | + |
| 57 | +### Fallible allocation |
| 58 | + |
| 59 | +Rust 1.57 stabilizes `try_reserve` for `Vec`, `String`, `HashMap`, `HashSet`, and `VecDeque`. This API enables callers to fallibly allocate the backing storage for these types. |
| 60 | + |
| 61 | +Rust will usually abort the process if the global allocator fails, which is not always desirable. This API provides a method for avoiding that abort when working with the standard library collections. However, Rust does not guarantee that the returned memory is actually allocated by the kernel: for example, if overcommit is enabled on Linux, the memory may not be available when its use is attempted. |
| 62 | + |
| 63 | +### Stabilized APIs |
| 64 | + |
| 65 | +The following methods and trait implementations were stabilized. |
| 66 | + |
| 67 | +- [`[T; N]::as_mut_slice`][`array::as_mut_slice`] |
| 68 | +- [`[T; N]::as_slice`][`array::as_slice`] |
| 69 | +- [`collections::TryReserveError`] |
| 70 | +- [`HashMap::try_reserve`] |
| 71 | +- [`HashSet::try_reserve`] |
| 72 | +- [`String::try_reserve`] |
| 73 | +- [`String::try_reserve_exact`] |
| 74 | +- [`Vec::try_reserve`] |
| 75 | +- [`Vec::try_reserve_exact`] |
| 76 | +- [`VecDeque::try_reserve`] |
| 77 | +- [`VecDeque::try_reserve_exact`] |
| 78 | +- [`Iterator::map_while`] |
| 79 | +- [`iter::MapWhile`] |
| 80 | +- [`proc_macro::is_available`] |
| 81 | +- [`Command::get_program`] |
| 82 | +- [`Command::get_args`] |
| 83 | +- [`Command::get_envs`] |
| 84 | +- [`Command::get_current_dir`] |
| 85 | +- [`CommandArgs`] |
| 86 | +- [`CommandEnvs`] |
| 87 | + |
| 88 | +The following previously stable functions are now `const`. |
| 89 | + |
| 90 | +- [`hint::unreachable_unchecked`] |
| 91 | + |
| 92 | +### Other changes |
| 93 | + |
| 94 | +There are other changes in the Rust 1.57.0 release: check out what changed in |
| 95 | +[Rust](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1570-2021-12-02), |
| 96 | +[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-157-2021-12-02), |
| 97 | +and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-157). |
| 98 | + |
| 99 | +### Contributors to 1.57.0 |
| 100 | + |
| 101 | +Many people came together to create Rust 1.57.0. |
| 102 | +We couldn't have done it without all of you. |
| 103 | +[Thanks!](https://thanks.rust-lang.org/rust/1.57.0/) |
| 104 | + |
| 105 | +[`array::as_mut_slice`]: https://doc.rust-lang.org/std/primitive.array.html#method.as_mut_slice |
| 106 | +[`array::as_slice`]: https://doc.rust-lang.org/std/primitive.array.html#method.as_slice |
| 107 | +[`collections::TryReserveError`]: https://doc.rust-lang.org/std/collections/struct.TryReserveError.html |
| 108 | +[`HashMap::try_reserve`]: https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#method.try_reserve |
| 109 | +[`HashSet::try_reserve`]: https://doc.rust-lang.org/std/collections/hash_set/struct.HashSet.html#method.try_reserve |
| 110 | +[`String::try_reserve`]: https://doc.rust-lang.org/alloc/string/struct.String.html#method.try_reserve |
| 111 | +[`String::try_reserve_exact`]: https://doc.rust-lang.org/alloc/string/struct.String.html#method.try_reserve_exact |
| 112 | +[`Vec::try_reserve`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try_reserve |
| 113 | +[`Vec::try_reserve_exact`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try_reserve_exact |
| 114 | +[`VecDeque::try_reserve`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.try_reserve |
| 115 | +[`VecDeque::try_reserve_exact`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.try_reserve_exact |
| 116 | +[`Iterator::map_while`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.map_while |
| 117 | +[`iter::MapWhile`]: https://doc.rust-lang.org/std/iter/struct.MapWhile.html |
| 118 | +[`proc_macro::is_available`]: https://doc.rust-lang.org/proc_macro/fn.is_available.html |
| 119 | +[`Command::get_program`]: https://doc.rust-lang.org/std/process/struct.Command.html#method.get_program |
| 120 | +[`Command::get_args`]: https://doc.rust-lang.org/std/process/struct.Command.html#method.get_args |
| 121 | +[`Command::get_envs`]: https://doc.rust-lang.org/std/process/struct.Command.html#method.get_envs |
| 122 | +[`Command::get_current_dir`]: https://doc.rust-lang.org/std/process/struct.Command.html#method.get_current_dir |
| 123 | +[`CommandArgs`]: https://doc.rust-lang.org/std/process/struct.CommandArgs.html |
| 124 | +[`CommandEnvs`]: https://doc.rust-lang.org/std/process/struct.CommandEnvs.html |
| 125 | +[`hint::unreachable_unchecked`]: https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html |
0 commit comments