Language
- The 2021 Edition is now stable. See the edition guide for more details.
- The pattern in
binding @ pattern
can now also introduce new bindings. - Union field access is permitted in
const fn
.
Compiler
- Upgrade to LLVM 13.
- Support memory, address, and thread sanitizers on aarch64-unknown-freebsd.
- Allow specifying a deployment target version for all iOS targets
- Warnings can be forced on with
--force-warn
. This feature is primarily intended for usage bycargo fix
, rather than end users. - Promote
aarch64-apple-ios-sim
to Tier 2*. - Add
powerpc-unknown-freebsd
at Tier 3*. - Add
riscv32imc-esp-espidf
at Tier 3*.
* Refer to Rust's platform support page for more information on Rust's tiered platform support.
Libraries
- Allow writing of incomplete UTF-8 sequences via stdout/stderr on Windows. The Windows console still requires valid Unicode, but this change allows splitting a UTF-8 character across multiple write calls. This allows, for instance, programs that just read and write data buffers (e.g. copying a file to stdout) without regard for Unicode or character boundaries.
- Prefer
AtomicU{64,128}
over Mutex for Instant backsliding protection. For this use case, atomics scale much better under contention. - Implement
Extend<(A, B)>
for(Extend<A>, Extend<B>)
- impl Default, Copy, Clone for std::io::Sink and std::io::Empty
impl From<[(K, V); N]>
for all collections.- Remove
P: Unpin
bound on impl Future for Pin. - Treat invalid environment variable names as non-existent. Previously, the environment functions would panic if given a variable name with an internal null character or equal sign (
=
). Now, these functions will just treat such names as non-existent variables, since the OS cannot represent the existence of a variable with such a name.
Stabilised APIs
std::os::unix::fs::chroot
UnsafeCell::raw_get
BufWriter::into_parts
core::panic::{UnwindSafe, RefUnwindSafe, AssertUnwindSafe}
These APIs were previously stable instd
, but are now also available incore
.Vec::shrink_to
String::shrink_to
OsString::shrink_to
PathBuf::shrink_to
BinaryHeap::shrink_to
VecDeque::shrink_to
HashMap::shrink_to
HashSet::shrink_to
These APIs are now usable in const contexts:
Cargo
- Cargo supports specifying a minimum supported Rust version in Cargo.toml. This has no effect at present on dependency version selection. We encourage crates to specify their minimum supported Rust version, and we encourage CI systems that support Rust code to include a crate's specified minimum version in the test matrix for that crate by default.
Compatibility notes
- Update to new argument parsing rules on Windows. This adjusts Rust's standard library to match the behavior of the standard libraries for C/C++. The rules have changed slightly over time, and this PR brings us to the latest set of rules (changed in 2008).
- Disallow the aapcs calling convention on aarch64 This was already not supported by LLVM; this change surfaces this lack of support with a better error message.
- Make
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS
warn by default - Warn when an escaped newline skips multiple lines.
- Calls to
libc::getpid
/std::process::id
fromCommand::pre_exec
may return different values on glibc <= 2.24. Rust now invokes theclone3
system call directly, when available, to use new functionality available via that system call. Older versions of glibc cache the result ofgetpid
, and only update that cache when calling glibc's clone/fork functions, so a direct system call bypasses that cache update. glibc 2.25 and newer no longer cachegetpid
for exactly this reason.
Internal changes
These changes provide no direct user facing benefits, but represent significant improvements to the internals and overall performance of rustc and related tools.
- LLVM is compiled with PGO in published x86_64-unknown-linux-gnu artifacts. This improves the performance of most Rust builds.
- Unify representation of macros in internal data structures. This change fixes a host of bugs with the handling of macros by the compiler, as well as rustdoc.