Stable Release in branch 1.35
1.35.0
Released 23 May 2019
(7 years ago)
SoftwareRust
Version1.35
Initial release1.35.0
23 May 2019
(7 years ago)
Latest release1.35.0
23 May 2019
(7 years ago)
Support status04 Jul 2019
(Ended 7 years ago)
Release noteshttps://github.com/rust-lang/rust/releases/tag/1.35.0
Source codehttps://github.com/rust-lang/rust/tree/1.35.0
Downloadhttps://github.com/rust-lang/rust/releases/tag/1.35.0
Rust 1.35 ReleasesView full list

What Is New in Rust 1.35

CategoryHighlights
New FeaturesFn* traits for Box, coercion of closures to unsafe fn pointers, dbg!() without arguments, several std library stabilizations (copysign, Range::contains, RefCell mapping/split, replace_with, ptr::hash, Option::copied)
ImprovementsClippy added drop_bounds lint and split redundant_closure lint; Cargo received various internal updates

How can I store and call a closure inside a Box without using FnBox?

In Rust 1.35 you can store any closure in a Box and call it directly because Box now implements the Fn, FnMut, and FnOnce traits.

  • Boxed closures can be passed to APIs that expect a generic Fn trait.
  • No more need for the unstable FnBox helper.
fn apply(x: Box<dyn Fn(u8) -> u8>) -> Vec<u8> {
    vec![1, 2, 3, 4].into_iter().map(x).collect()
}

fn call_once(f: Box<dyn FnOnce()>) {
    f();
}

In practice this reduces boilerplate and makes higher-order functions that own closures ergonomic.

Can I coerce a non-capturing closure into an unsafe function pointer?

Yes, Rust 1.35 extends the existing coercion rules so that a closure which does not capture its environment can be turned into an unsafe fn pointer.

  • This works for both safe and unsafe function pointer types.
  • The closure must be statically proven not to perform any unsafe actions.
unsafe fn call_unsafe(f: unsafe fn()) {
    f();
}

fn main() {
    unsafe {
        call_unsafe(|| {
            dbg!();
        });
    }
}

This matters if you need to pass a closure to a C-FFI callback that expects an unsafe function pointer.

What new standard-library APIs landed in Rust 1.35?

Rust 1.35 stabilizes a handful of small but frequently-used methods that make everyday code clearer.

  • Floating-point sign copy: f32::copysign and f64::copysign copy the sign of one number onto another.
  • Range containment: Range::contains and RangeInclusive::contains let you test membership with (0..=10).contains(&5).
  • RefCell ergonomics: RefCell::map_split splits a borrow into two independent borrows, and RefCell::replace_with replaces the inner value via a closure while returning the old value.
  • Pointer hashing: ptr::hash hashes the address of a raw pointer instead of the pointed-to value.
  • Option copying: Option::copied works like cloned but requires T: Copy, giving a compile-time guarantee.

These additions are zero-cost abstractions that improve readability without sacrificing performance.

How does the dbg! macro behave when called without arguments?

In Rust 1.35 the dbg! macro can be invoked with no arguments, printing only the source location.

fn main() {
    let condition = true;
    if condition {
        dbg!();
    }
}

The output looks like [src/main.rs:5], which is handy for tracing control-flow without needing to print a value.

Frequently Asked Questions

Does Rust 1.35 allow calling boxed closures directly?
Yes, you can call a Box<dyn FnOnce()> directly with x().

Can I coerce a non-capturing closure to an unsafe fn pointer in Rust 1.35?
Yes, a closure like || {} can be coerced to unsafe fn() and passed to functions expecting unsafe fn().

What method replaces FnBox for boxed closures in Rust 1.35?
The implementation of the Fn, FnMut, and FnOnce traits for Box removes the need for FnBox.

How do I check if a value is inside a range using the new API?
Use (0..=10).contains(&5) which returns true if 5 is in the range.

Which new Option method copies values instead of cloning them?
Option::copied works for Option<&T> where T: Copy and copies the value.

What does the dbg! macro output when called without arguments?
It prints the source location line like [src/main.rs:5] with no value.

Releases In Branch 1.35

VersionRelease date
1.35.023 May 2019
(7 years ago)