Rust 1.64.0, unveiled September 22, 2022, stabilizes the IntoFuture
trait, to enhance .await
and improve APIs. IntoFuture
is similar to the IntoIterator
trait, but instead of supporting for … in …
loops, IntoFuture
changes how .await
works.
With IntoFuture
, the .await
keyword can await more than just features; it can await anything that can be converted into a Future
via IntoFuture
, to help make APIs more user-friendly. For the future, the developers of Rust hope to simplify development of new named futures by supporting impl Trait
in type
aliases. This should make implementing IntoFuture
easier by simplifying the type
alias signature and make it more performant by removing the Box
from the type
alias.
Also in Rust 1.64:
- The language provides all
c_*
type aliases incore::ffi
, as well ascore::ffi::CStr
, for working with C strings. Rust 1.64 also providesalloc::ffi::CString
for working with owned C strings using only thealloc
crate rather than the fullstd
library. - rust-analyzer, an implementation of the Language Server protocol for Rust, now is included as part of the collection of tools included with Rust. This makes it easier to download and access rust-analyzer and makes it available on more platforms. The tool is available as a rustup component and can be installed with the command
rustup component add rust_analyzer
. - When working with collections of related libraries or binary crates in one Cargo workspace, developers now can avoid duplication of common field values between crates, such as common version numbers or repository URLs.
- The memory layouts of
Ipv6Addr
,Ipv4Addr
,SocketAddrV4
, andSocketAddrV6
have been changed to be more memory efficient and compact. - Windows builds of the Rust compiler now use profile-guided optimization, improving performance.
- A number of methods and trait implementations have been stabilized, including
num::NonZero*::checked_mul
,num::NonZero*::checked_pow
, and many others.
The new features in Rust 1.63
Published August 11, 2022, Rust 1.63 adds scoped threads to the standard library. Scoped threads allow you to spawn a thread by borrowing from the local stack frame. The std::thread::scope
API provides a guarantee that any spawned threads will have exited prior to its returning, allowing for safely borrowing data. Rust 1.63 also enables non-lexical lifetimes (NLL) by default; the feature is now fully stable. NLL is the second iteration of Rust’s borrow checker.
Also in Rust 1.63:
- For I/O safety, wrapper types are provided such as
BorrowedFD
andOwnedFD
, which are marked as#[repr(transparent)]
, meaning thatextern "C"
bindings can take these types to encode ownership semantics. - The
Condvar::New
,Mutex::New
, andRwLock::new
functions are now callable inconst
contexts, to avoid the use of crates such as lazy_static for creating global statics withMutex
,RwLock
, orCondvar
. This builds on work in Rust 1.62 to enable faster and thinner mutexes. - A number of APIs were stabilized including
array::from_fn
,Box::into_pin
, andPath::try_exists
.
The new features in Rust 1.62
Rust 1.62, which arrived June 30, 2022, lets developers add dependencies directly from the command line using cargo add
. This command supports specifying versions and features and also can modify existing dependencies. Rust 1.62 also allows the use of #[derive(Default)] on enums if a default variant is specified.
Other new capabilities in Rust 1.62:
- Rust’s standard library now ships with a raw futex-based implementation of locks on Linux, which is lightweight and does not carry any extra allocation. This addition is part of an effort to improve the efficiency of Rust lock types.
- It is now easier to build OS-less binaries for x86_64, for example when writing a kernel. The x86_64-unknown-none target has been promoted to Tier 2 and can be installed with rustup.
- A number of APIs have been stabilized including bool::then_some, f32::total_cmp, f64::total_cmp, and Stdin::lines.
The new features in Rust 1.61
Published May 19, 2022, Rust 1.61 highlights custom exit codes from main
. Rust proponents said that in the beginning, Rust main
functions only could return the unit type ()
either implicitly or explicitly, indicating success in the exit status, and if developers wanted otherwise, they had to call process::exit
. Since Rust 1.26, main
has been allowed to return a Result
, where Ok
translated to a C EXIT_SUCCESS
and Err
to EXIT_Failure
. These alternate return types were unified by an unstable Termination trait. In this release, Termination
trait is stable, along with a more-general ExitCode
type that wraps platform-specific return types. The Termination
trait also can be implemented for a developer’s own types, allowing for customization of reporting before converting to an ExitCode
.
Also in Version 1.61:
- Several incremental features have been stabilized to enable more functionality in
const
. Developers now can create, pass, and cast function pointers in aconst fn
, which could be useful to build compile-time function tables for an interpreter. But it is still not permitted to callfn
pointers. Developers also now can write trait bounds on generic parameters toconst fn
, such asT: Copy
, where previously onlySized
was permitted. Also,const fn
now can deal with trait objects, whereas arguments and return values forconst fn
can be opaqueimpl Trait
types. - APIs have been stabilized such as
Pin::static_mut
,Pin;;static_ref
, andVec::retain_mut
. - Previously, the creation of locked handles to
stdin/stdlout/stderr
would borrow the handles being locked, which prevented writinglet out = std::io::stdout().lock();
becauseout
would outlive the return value ofstdout()
. This code now works, eliminating a common pitfall affecting many Rust users.
The new features in Rust 1.60.0
Rust 1.60, introduced April 7, 2022, stabilizes support for LLVM-based coverage instrumentation in rustc
. This provides for source-based code coverage. Developers can try this out by rebuilding their code with -Cinstrument-coverage
. Afterward, running the resulting binary will produce a default.profraw file in the current directory.
The llvm-tools-preview
component includes llvm-profdata
for processing and merging raw profile output, llvm-profdata
for processing raw file output, and llvm-cov
for report generation. Baseline functionality is stable and will exist in all future Rust releases, but the specific output format and LLVM tools that produce it are subject to change. Developers should use the same version for both llvm-tools-preview
and the rustc
binary used to compile code.
Rust 1.60 also re-enables incremental compilation. The Rust team continues to work on fixing bugs in incremental but no problems causing widespread breakage are known at this time.
Also in Rust 1.60:
- On all platforms,
Instant
will try to use an operating system API that guarantees monotonic behavior if available. In practice, such guarantees are, under rare circumstances, broken by hardware, virtualization, or operating system bugs. To work around these bugs, and to work with platforms that lack monotonic clocks,Instant::duration_since
,Instant::elapsed
, andInstant::sub
now saturate to zero. In older versions of Rust, this led to a panic, instead. - Cargo has established support for collecting information on build with the
--timings
flag. - Namespaced dependencies and weak dependency features have been introduced to improve support for Cargo features and how they interact with optional dependencies. Cargo features provide a mechanism to express conditional compilation and optional dependencies.
- A number of APIs have been stabilized such as
Arc::new_cyclic
,Rc::new_cyclic
, andslice::EscapAscii
.
The new features in Rust 1.59.0
Rust 1.59.0 was announced on February 24, 2022. A key feature is support for inline assembly, enabling many applications that need very low-level control over execution or access to specialized machine instructions. Assembly language and instructions available with inline assembly vary according to architecture. The capability currently is supported on architectures including x86 and x64, ARM, Risc-V, and AArch64.
Other new features and improvements in Rust 1.59.0:
- Developers now can use slice, tuple, and struct patterns as the left-hand side of an assignment, making assignment more consistent with
let
bindings, which already support these patterns. - Generic types now can specify default values for
const
generics. - The Cargo package manager now shows warnings when a dependency will be rejected by a future version of Rust.
- For the creation of stripped binaries, cargo and rustc now support stripping when the binary is linked. Rust’s developers said it is often useful to strip unnecessary information like buginfo from binaries that are distributed, making them smaller.
- Incremental compilation is off by default. This mitigates the effect of a known bug that causes deserialization errors. A fix for this bug will be available in the Rust 1.60 beta due in six weeks.
- A number of APIs have been stabilized.
The new features in Rust 1.58.1
This point release arriving January 20, 2022, just days after Rust 1.58, fixes a race condition in the std::fs::remove_dir_all
standard library function. This vulnerability is tracked at CVE-2022-21658 and there was an advisory published. An attacker could use this security issue to trick a privileged program into deleting files and directories that the attacker otherwise could not access or delete. Rust versions 1.0 through 1.58 are affected by this vulnerability. Users are advised to update their toolchains and build programs with the updated compiler.
Rust 1.58.1 also addresses several regressions in diagnostics and tools introduced in Rust 1.58:
- The
non_send_fields_in_send_ty
Clippy lint was found to have too many false positives and has been moved to the experimental lints group called “nursery”. - The
useless_format
Clippy lint was updated to handle captured identifiers in format strings, introduced in Rust 1.58. - A regression in
Rustfmt
preventing generated files from being formatted when passed through the standard input has been fixed. - An incorrect error message displayed by
rustc
in some cases has been fixed.
The new features in Rust 1.58
Rust 1.58, announced January 13, 2022, features captured identifiers in format strings. With this capability, format strings now can capture arguments by writing {ident}
in the string. Formats long have accepted positional arguments and named arguments, such as:
println!("Hello, {}!", get_person()); // implicit position
println!("Hello, {0}!", get_person()); // explicit index
println!("Hello, {person}!", person = get_person()); // named
Now, named arguments also can be captured from the surrounding scope.
Also new in Rust 1.58: On Windows targets, std::process::Command
will no longer search the current directory for executables, which was an effect of the historical behavior of the win32 CreateProcess
API. This fixes a situation in which searches could lead to surprising behavior or malicious results when dealing with untrusted directories.
Rust 1.58 also introduces more #[must_use]
in the standard library. The #[must use]
attribute can be applied to types or functions when failing to explicitly consider them or their output is almost certainly a bug. Rust 1.58 also has stabilized APIs such as Metadata::is_symlinkcode
and Path::is_symlink
.
The new features in Rust 1.57
Rust 1.57, unveiled December 2, 2021, brings panic!
(for terminating a program in an unrecoverable state) to const
contexts. Previously, the panic!
macro was not usable in const fn
and other compile-time contexts. This has now been stabilized. Together with the stabilization of panic!
, several other standard libraries now are usable in const
, such as assert!
. But this stabilization does not yet include the full formatting infrastructure. The panic!
macro must be called with either a static string or a single interpolated value to be used with {}
. This support is expected to expand in the future.
Other new features and improvements in Rust 1.57:
- Cargo adds support for arbitrarily named profiles.
try_reserve
has been stabilized forVec
,String
,HashMap
,HashSet
, andVecDeque
. This API enables callers to fallibly allocate backing storage for these types.- Multiple other APIs have been stabilized including
[T; N]::as_mut_slice
and[T; N]::as_slice
. - Macro attributes now may follow
#derive
and will see the original input.
The new features in Rust 1.56
Announced October 21, 2021, Rust 1.56 is the first version of the language that supports the Rust 2021 edition. The Rust 2021 edition lets Rust crate authors opt in to breaking language changes that make Rust easier to use and more consistent. Crates can opt in at any time and remain interoperable with crates in older editions. The Rust compiler supports all three editions of the language: 2015, 2018, and 2021.
Other new capabilities in Rust 1.56 include: