Email me

Rust versions / 1.61

Rust release · May 19, 2022

Rust 1.61: what's new, what was stabilized

Short answerRust 1.61 was released on May 19, 2022: 17 newly stable APIs (Pin::static_mut, Pin::static_ref, Vec::retain_mut, VecDeque::retain_mut, ...); 8 compatibility notes that can affect existing code.

May 19, 2022release date
0language stabilizations
17APIs stabilized
-new edition

← Rust 1.60All versionsRust 1.62 →

17 APIs stabilized

Pin::static_mut, Pin::static_ref, Vec::retain_mut, VecDeque::retain_mut, Write, std::os::unix::net::SocketAddr::from_pathname, std::process::ExitCode, std::thread::JoinHandle::is_finished, <*const T>::offset, <*const T>::wrapping_offset, <*const T>::add, <*const T>::sub, <*const T>::wrapping_add, <*const T>::wrapping_sub, <[T]>::as_mut_ptr, <[T]>::as_ptr_range, <[T]>::as_mut_ptr_range

Can it break my build?

The release lists these compatibility notes. Most only affect rare code, but read them before you raise your toolchain in CI:

  • Previously native static libraries were linked as whole-archive in some cases, but now rustc tries not to use whole-archive unless explicitly requested. This [change][93901] may result in linking errors in some cases. To fix such errors, native libraries linked from the command line, build scripts, or [#[link] attributes][link-attr] need to
  • [Catching a second unwind from FFI code while cleaning up from a Rust panic now causes the process to abort][92911]
  • [Proc macros no longer see ident matchers wrapped in groups][92472]
  • [The number of # in r# raw string literals is now required to be less than 256][95251]
  • [When checking that a dyn type satisfies a trait bound, supertrait bounds are now enforced][92285]
  • [cargo vendor now only accepts one value for each --sync flag][cargo/10448]
  • [cfg predicates in all() and any() are always evaluated to detect errors, instead of short-circuiting.][94295] The compatibility considerations here arise in nightly-only code that used the short-circuiting behavior of all to write something like cfg(all(feature = "nightly", syntax-requiring-nightly)), which will now fail to compile. Instead, use either cfg_attr(feature = "nightly", ...) or nested uses of cfg.
  • [bootstrap: static-libstdcpp is now enabled by default, and can now be disabled when llvm-tools is enabled][94832]

Use it

rustup update stable        # get the newest release
rustup install 1.61          # or exactly this one
rustup override set 1.61     # pin a project to it

To require at least this version from users of your crate, set rust-version = "1.61" under [package] in Cargo.toml. Cargo then refuses to build it on older compilers with a clear message, and with resolver 3 (the default on the 2024 edition, Rust 1.85+) it also prefers dependency versions that support it.

Full release notes

Language

  • [const fn signatures can now include generic trait bounds][93827]
  • [const fn signatures can now use impl Trait in argument and return position][93827]
  • [Function pointers can now be created, cast, and passed around in a const fn][93827]
  • [Recursive calls can now set the value of a function's opaque impl Trait return type][94081]

Compiler

  • [Linking modifier syntax in #[link] attributes and on the command line, as well as the whole-archive modifier specifically, are now supported][93901]
  • [The char type is now described as UTF-32 in debuginfo][89887]
  • The [#[target_feature]][target_feature] attribute [can now be used with aarch64 features][90621]
  • X86 [#[target_feature = "adx"] is now stable][93745]

Libraries

  • [ManuallyDrop<T> is now documented to have the same layout as T][88375]
  • [#[ignore = "…"] messages are printed when running tests][92714]
  • [Consistently show absent stdio handles on Windows as NULL handles][93263]
  • [Make std::io::stdio::lock() return 'static handles.][93965] Previously, the creation of locked handles to stdin/stdout/stderr would borrow the handles being locked, which prevented writing let out = std::io::stdout().lock(); because out would outlive the return value of stdout(). Such code now works, eliminating a common pitfall that affected many Rust users.
  • [Vec::from_raw_parts is now less restrictive about its inputs][95016]
  • [std::thread::available_parallelism now takes cgroup quotas into account.][92697] Since available_parallelism is often used to create a thread pool for parallel computation, which may be CPU-bound for performance, available_parallelism will return a value consistent with the ability to use that many threads continuously, if possible. For instance, in a container with 8 virtual CPUs but quotas only allowing for 50% usage, available_parallelism will return 4.

Stabilized APIs

  • [Pin::static_mut]
  • [Pin::static_ref]
  • [Vec::retain_mut]
  • [VecDeque::retain_mut]
  • [Write for Cursor<[u8; N]>][cursor-write-array]
  • [std::os::unix::net::SocketAddr::from_pathname]
  • [std::process::ExitCode] and [std::process::Termination]. The stabilization of these two APIs now makes it possible for programs to return errors from main with custom exit codes.
  • [std::thread::JoinHandle::is_finished]

These APIs are now usable in const contexts:

  • [<*const T>::offset and <*mut T>::offset][ptr-offset]
  • [<*const T>::wrapping_offset and <*mut T>::wrapping_offset][ptr-wrapping_offset]
  • [<*const T>::add and <*mut T>::add][ptr-add]
  • [<*const T>::sub and <*mut T>::sub][ptr-sub]
  • [<*const T>::wrapping_add and <*mut T>::wrapping_add][ptr-wrapping_add]
  • [<*const T>::wrapping_sub and <*mut T>::wrapping_sub][ptr-wrapping_sub]
  • [<[T]>::as_mut_ptr][slice-as_mut_ptr]
  • [<[T]>::as_ptr_range][slice-as_ptr_range]
  • [<[T]>::as_mut_ptr_range][slice-as_mut_ptr_range]

Cargo

No feature changes, but see compatibility notes.

Compatibility Notes

  • Previously native static libraries were linked as whole-archive in some cases, but now rustc tries not to use whole-archive unless explicitly requested. This [change][93901] may result in linking errors in some cases. To fix such errors, native libraries linked from the command line, build scripts, or [#[link] attributes][link-attr] need to
  • (more common) either be reordered to respect dependencies between them (if a depends on b then a should go first and b second)
  • (less common) or be updated to use the [+whole-archive] modifier.
  • [Catching a second unwind from FFI code while cleaning up from a Rust panic now causes the process to abort][92911]
  • [Proc macros no longer see ident matchers wrapped in groups][92472]
  • [The number of # in r# raw string literals is now required to be less than 256][95251]
  • [When checking that a dyn type satisfies a trait bound, supertrait bounds are now enforced][92285]
  • [cargo vendor now only accepts one value for each --sync flag][cargo/10448]
  • [cfg predicates in all() and any() are always evaluated to detect errors, instead of short-circuiting.][94295] The compatibility considerations here arise in nightly-only code that used the short-circuiting behavior of all to write something like cfg(all(feature = "nightly", syntax-requiring-nightly)), which will now fail to compile. Instead, use either cfg_attr(feature = "nightly", ...) or nested uses of cfg.
  • [bootstrap: static-libstdcpp is now enabled by default, and can now be disabled when llvm-tools is enabled][94832]

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.

Release notes from the Rust project's RELEASES.md (MIT or Apache-2.0); summaries above are ours.

← Rust 1.60All versionsRust 1.62 →

Up next

Next releaseRust 1.62Released Jun 30, 2022.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ