Latest in branch 1.61
1.61.0
Released 19 May 2022
(4 years ago)
SoftwareRust
Version1.61
Initial release1.61.0
19 May 2022
(4 years ago)
Latest release1.61.0
19 May 2022
(4 years ago)
Support status01 Jul 2022
(Ended 3 years, 11 months ago)
Release noteshttps://github.com/rust-lang/rust/releases/tag/1.61.0
Source codehttps://github.com/rust-lang/rust/tree/1.61.0
Downloadhttps://github.com/rust-lang/rust/releases/tag/1.61.0
Rust 1.61 ReleasesView full list

What Is New in Rust 1.61

CategoryHighlights
New FeaturesTermination trait stabilised with ExitCode type, const fn now supports fn pointers, trait bounds, dyn Trait and impl Trait, stdio lock guards are 'static.
ImprovementsSeveral std functions became const, additional API stabilisations, minor ergonomics.

How can I return custom exit codes from main without calling process::exit?

Rust 1.61 lets you return a custom type from main by implementing the stable Termination trait.

This replaces the old pattern of calling std::process::exit and gives you type-safe exit handling.

use std::process::{ExitCode, Termination};

#[repr(u8)]
pub enum GitBisectResult {
    Good = 0,
    Bad = 1,
    Skip = 125,
    Abort = 255,
}

impl Termination for GitBisectResult {
    fn report(self) -> ExitCode {
        ExitCode::from(self as u8)
    }
}

fn main() -> GitBisectResult {
    // Your logic here
    GitBisectResult::Good
}

In practice, you can now map domain-specific outcomes directly to OS exit codes while keeping main ergonomic.

What new capabilities does const fn have in Rust 1.61?

Const functions can now work with function pointers, trait bounds, dyn Trait objects, and impl Trait return types.

  • Function pointers can be created, passed, and cast inside a const fn.
  • Generic parameters may now carry arbitrary trait bounds such as T: Copy.
  • Trait objects (dyn Trait) are allowed as arguments or locals.
  • Opaque return types (impl Trait) are supported.
const fn make_table() -> [fn(i32) -> i32; 2] {
    [|x| x + 1, |x| x * 2]
}

Note that calling a function pointer inside a const fn is still unstable, but the groundwork is laid for compile-time tables and dispatch.

Why are stdio lock guards now 'static and how does that affect my code?

The lock() methods on stdin, stdout, and stderr now return guards with a 'static lifetime.

This removes the previous "temporary value dropped while borrowed" error when you lock a handle in a single statement.

let out = std::io::stdout().lock(); // works now, guard is 'static

In practice, you can acquire a lock and store it for the duration of the program without needing an extra variable to keep the handle alive.

Which existing APIs became const in Rust 1.61?

A handful of stable functions were promoted to const, enabling their use in compile-time contexts.

  • slice::len
  • Option::is_some
  • Result::is_ok
  • Various iterator adapters that were previously non-const.

This matters if you are writing const-evaluated data structures or leveraging const fn for embedded initialization.

Frequently Asked Questions

Does Rust 1.61 require any changes to Cargo.toml for the new features?
No, the new features are part of the standard library and work on the stable channel without extra configuration.

Can I use the Termination trait on my own enum to map to specific exit codes?
Yes, you implement Termination for your type and return ExitCode::from(your_value) inside the report method.

Are function pointers callable inside const fn in Rust 1.61?
No, you can create and pass them but calling them remains unstable.

Will the 'static stdio lock guards break existing code that relied on the previous lifetime?
Existing code continues to compile; the change only relaxes the lifetime, so there is no breaking impact.

Which std functions became const in this release?
Functions such as slice::len, Option::is_some, and Result::is_ok were promoted to const.

How do I upgrade to Rust 1.61 on a CI server?
Run rustup update stable on the CI machine before building.

Releases In Branch 1.61

VersionRelease date
1.61.019 May 2022
(4 years ago)