Series: The Rust Annals
Vol. I Issue 44 nlopes.dev
Announcing Rust 1.43.0
Standard minor release with practical DX improvements and testing ergonomics, but lacks groundbreaking language features or major ecosystem shifts.
item fragments
In macros, you can use item fragments to interpolate items into the body of traits,
impls, and extern blocks. For example:
macro_rules! mac_trait {
($i:item) => {
trait T { $i }
}
}
mac_trait! {
fn foo() {}
}
This will generate:
trait T {
fn foo() {}
}
Type inference around primitives
The type inference around primitives, references, and binary operations was improved. A code sample makes this easier to understand: this code fails to compile on Rust 1.42, but compiles in Rust 1.43.
let n: f32 = 0.0 + &0.0;
In Rust 1.42, you would get an error that would say “hey, I don’t know how to add
an f64 and an &f64 with a result of f32.” The algorithm now correctly decides
that both 0.0 and &0.0 should be f32s instead.
New Cargo environment variable for tests
In a move to help integration testing, Cargo will set some new environment variables.
This is easiest to explain by example: let’s say we’re working on a command
line project, simply named “cli”. If we’re writing an integration test, we want
to invoke that cli binary and see what it does. When running tests and
benchmarks, Cargo will set an environment variable named CARGO_BIN_EXE_cli,
and I can use it inside my test:
let exe = env!("CARGO_BIN_EXE_cli");
This makes it easier to invoke cli, as we now have a path to it directly.
Library changes
You can now use associated constants on floats and integers directly, rather
than having to import the module. That is, you can now write u32::MAX or f32::NAN
with no use std::u32; or use std::f32;.
There is a new primitive
module that re-exports Rust’s
primitive types. This can be useful when you’re writing a macro and want to make
sure that the types aren’t shadowed.
Additionally, we stabilized six new APIs: