Series: The Rust Annals
Vol. I Issue 75 nlopes.dev
Announcing Rust 1.74.0
Rust 1.74 moves lint policy into Cargo manifests, adds credential providers and fully authenticated private registries, and permits Self and associated types in opaque return types. Together, these changes make workspace lint configuration easier to share, reduce the risk of registry-token leakage, and remove a former restriction from async fn and -> impl Trait.
Cargo manifests can define and share lint policy
As proposed in RFC 3389, Cargo.toml now supports a [lints] table for configuring the forbid, deny, warn, or allow level of lints from the compiler and other tools. Previously, projects could use RUSTFLAGS with -F, -D, -W, or -A, affecting the entire build, or add crate-level attributes:
#![forbid(unsafe_code)]
#![deny(clippy::enum_glob_use)]
The equivalent policy can now live in the package manifest:
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
enum_glob_use = "deny"
A workspace can configure the settings in [workspace.lints], with packages inheriting them through [lints] workspace = true. Cargo also tracks changes to these settings when deciding which crates need rebuilding. The Cargo reference documents the lints and workspace.lints tables.
Registry credentials gain secure providers and broader authentication
Credential providers make the way Cargo obtains registry credentials configurable. Built-in providers use OS-specific secure secret storage on Linux, macOS, and Windows, while custom providers can support arbitrary ways of storing or generating tokens. Using a secure credential provider reduces the risk of registry tokens leaking.
Registries may now require authentication for every operation rather than only for publishing, enabling private Cargo registries to offer more secure crate hosting. Using a private registry requires a credential provider. Further details are in the Cargo documentation.
Opaque return types can mention Self and associated types
The compiler now accepts Self and associated types in opaque return types such as async fn and -> impl Trait. This removes the former error that a “return type cannot contain a projection or Self that references lifetimes from a parent scope.”
The functionality remained behind an unstable feature gate because its original implementation did not properly handle captured lifetimes. After that was fixed, it was given time to ensure soundness. The stabilization pull request gives these examples, all of which are now allowed:
struct Wrapper<'a, T>(&'a T);
// Opaque return types that mention `Self`:
impl Wrapper<'_, ()> {
async fn async_fn() -> Self { /* ... */ }
fn impl_trait() -> impl Iterator<Item = Self> { /* ... */ }
}
trait Trait<'a> {
type Assoc;
fn new() -> Self::Assoc;
}
impl Trait<'_> for () {
type Assoc = ();
fn new() {}
}
// Opaque return types that mention an associated type:
impl<'a, T: Trait<'a>> Wrapper<'a, T> {
async fn mk_assoc() -> T::Assoc { /* ... */ }
fn a_few_assocs() -> impl Iterator<Item = T::Assoc> { /* ... */ }
}
The standard library adds conversions, encoded-byte access, and const support
This release stabilizes fifteen standard-library APIs and implementations. The final three entries in the inventory are newly stable in const contexts; the others are newly stable APIs.