Series: The Rust Annals
Vol. I Issue 44 nlopes.dev
Announcing Rust 1.43.0
Rust 1.43.0 is a fairly minor release with no new major features. Its small macro-related feature lets item fragments be interpolated into traits, impls, and extern blocks; improved inference accepts more expressions combining primitives, references, and binary operations; and Cargo now exposes binary paths to tests and benchmarks. Direct primitive associated constants, a module for unshadowed primitive types, six stabilized APIs, and compiler performance improvements round out the release.
Macros can interpolate items into more block bodies
Macros can now 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 generates:
trait T {
fn foo() {}
}
Primitive inference now accounts for the expected result type
Type inference around primitives, references, and binary operations was improved. The following code failed to compile on Rust 1.42 but compiles in Rust 1.43:
let n: f32 = 0.0 + &0.0;
Rust 1.42 reported that it did not 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.
Cargo gives tests and benchmarks the path to each binary
To help integration testing, Cargo now sets new environment variables when running tests and benchmarks. For a command-line project whose binary is named cli, Cargo sets CARGO_BIN_EXE_cli; a test can obtain its path directly:
let exe = env!("CARGO_BIN_EXE_cli");
This makes it easier for an integration test to invoke the binary and inspect what it does.
Primitive constants and types become easier to name
Associated constants on floats and integers can now be used directly. Code can write u32::MAX or f32::NAN without use std::u32; or use std::f32;.
The new primitive module re-exports Rust’s primitive types. This can be useful in a macro that needs to ensure those types have not been shadowed.
Six APIs were stabilized: