Series: The Rust Annals
Vol. I Issue 101 nlopes.dev
Announcing Rust 1.100.0
Rust 1.100 stabilizes the never type wherever a type can be named and stabilizes the core allocator API for use with Vec and Box.
Rust 1.100 stabilizes the never type, !, wherever a type can be named. For example, a function signature can now use Result<T, !>. Rust 1.100 also stabilizes the core parts of the allocator API. Library authors can now define custom allocators and use them with Vec and Box. Cargo now reports unused dependencies when it builds every build target that may use them. Cargo also applies the build-configuration hash to all build-dir content. Projects can opt into a minimum publish age for newly published dependency versions.
The never type can appear anywhere a type can be named
After 10 years and five failed stabilization attempts, ! is stable wherever a type can be named. This completes the never type project goal.
The never type, !, is Rust’s canonical uninhabited type. It is the type of diverging computations. A diverging computation never resolves to a value. Any code that follows it is unreachable. Expressions that terminate control flow also have type !. Examples are return, break, and a call to std::process::exit. Unlike other uninhabited types, ! can coerce to any type. Because of this coercion, one branch of a match or if can exit without producing the value that the surrounding expression expects. See the never type documentation and the std::process::exit documentation.
fn mrrrow(option: Option<u32>) {
let value = match option {
// `x` has type `u32`
Some(x) => x,
// `return` has type `!`, which is then coerced to `u32`,
// allowing the `match` to pass type checking.
None => return,
};
// ...
}Stable Rust already supported this coercion. It also allowed naming the never type in a function return type, as in -> !. Rust 1.100 allows naming the never type anywhere, for example in Result<T, !>:
fn infallible_unwrap<T>(res: Result<T, !>) -> T {
// ^^ writing `Result<_, !>` was not allowed before
let Ok(v) = res;
v
}Rust 1.100 changes Infallible to be an alias for !. As a result, existing APIs that used Infallible are compatible with !. This alias was the plan ever since the introduction of Infallible. It is also one of the reasons why the never type stabilization was so hard. See the Infallible documentation and waffle’s talk about some of the troubles of the stabilization.
To allow the change to Infallible, Rust 1.100 introduces a breaking change. Never type fallback now uses ! in place of () in editions 2015, 2018, and 2021. Edition 2024 already made this change. The change should largely be unnoticeable. It can affect code in some rare cases, for example when code ignores the result of a function that returns a generic parameter. It might also let the compiler detect more code as unreachable. The Rust project issued future compatibility warnings well in advance and released fixes for affected public crates. See the edition guide on never type fallback.
Library authors can define custom allocators for use with Vec and Box
Rust 1.100 stabilizes the core parts of allocator_api. Library authors can implement the newly stable Allocator trait to define custom allocators. Custom allocators currently work with two standard-library types: Vec and Box. This stabilization is the foundation of the Allocators 1.0 project goal. Future work includes a larger API surface that is usable with custom allocators. It also includes stable use of custom allocators with more collections and pointer types. See the allocator_api tracking issue and the Allocators 1.0 project goal.
DropGuard runs a closure on every exit path
The Drop trait runs code when a variable goes out of scope, whether the code returns, uses ?, or panics. Because cleanup is part of the type, Rust code never has to close a socket. See Rust means never having to close a socket.
A Drop implementation can feel inconvenient when code only needs to run something unconditionally when a function exits. Rust 1.100 adds core::mem::DropGuard, a helper type that runs a closure when it is dropped. DropGuard::new takes a value and a closure. The guard implements Deref and DerefMut. Code can keep working with the inner value through the guard. When the guard is dropped, it runs the closure and consumes the value.
DropGuard::dismiss returns the inner value without running the closure. dismiss is deliberately an associated function, not a method. As a method, its name could collide with methods of the inner type that are reachable through DerefMut. In the following parser, the guard rolls back the pushes if an error occurs. If parsing succeeds, the function dismisses the guard.
use std::mem::DropGuard;
use std::num::ParseIntError;
/// Attempt to parse all `strings` and push them into `nums`.
/// If parsing any of them fails, `nums` remains unchanged.
fn parse_all(nums: &mut Vec<u32>, strings: &[&str]) -> Result<(), ParseIntError> {
let len = nums.len();
let mut nums = DropGuard::new(nums, move |nums| {
nums.truncate(len); // ← 1. Reset the vec on failure
});
for s in strings {
nums.push(s.parse()?); // ← 2. If `?` returns an error, roll back
}
DropGuard::dismiss(nums); // ← 3. Parsing successful, dismiss the guard
Ok(())
}
conjure_zst constructs zero-sized values in unsafe code
Rust’s unsafe code guidelines are still being decided. Rust 1.100 adds std::mem::conjure_zst. It is the dedicated way to construct a value of a zero-sized type when the caller knows that doing so is safe. Code can use conjure_zst instead of transmuting (), calling MaybeUninit::uninit().assume_init(), or other techniques.
A value of an inhabited zero-sized type contains no data. However, APIs often rely for safety on the fact that callers cannot construct such a value. For example, PyO3’s zero-sized Python<'py> token represents holding Python’s global interpreter lock. Many Python APIs require the lock for safety. If code could create the token from nothing, safe PyO3 calls could violate that precondition. That is why conjure_zst is unsafe. See the unsafe code guidelines, the conjure_zst documentation, and the PyO3 Python token documentation.
Cargo reports unused dependencies
Dependencies that are no longer used, or that are needed only for specific platforms, can slow down builds. Rustc has the unused_crate_dependencies lint for this. However, the lint has false positives when used with Cargo, because dependencies may be shared between multiple build targets. For example, dependencies.tracing-subscriber is available to every bin in a package even when only some may use it. Cargo now reports unused dependencies to users, for example:
warning: unused dependency `tracing-subscriber`
--> Cargo.toml:23:1
|
23 | tracing-subscriber.workspace = true
| ^^^^^^^^^^^^^^^^^^
|
= note: `cargo::unused_dependencies` is set to `warn` by default
help: consider removing the dependency on `tracing-subscriber`The warning appears only when Cargo builds every build target that may use an entry in a dependencies table. For example, cargo check --bin foo shows no warning for unused [dependencies], because another bin may use them. Cargo shows no warning for unused dev-dependencies, because there is no way to ensure that every development build target is built.
Cargo introduces this warning as part of a new linting system. The [lints.cargo] table in Cargo.toml controls that system. This warning completes the Cargo lints project goal. See the Cargo lint reference for the other lints that have been introduced.
Cargo applies the build-configuration hash to all build-dir content
Cargo builds libraries and binaries in build-dir and places final artifacts in target-dir. The directories currently share a common parent. Different build configurations, such as different --features, can produce different copies of libraries and binaries in build-dir. A build-configuration hash keeps these copies unique. Before Rust 1.100, platform constraints prevented Cargo from always applying the hash. A missing hash can lead to problems such as extra rebuilds, missed rebuilds, and confusion over which binaries or libraries are used. These problems get worse when Git worktrees share a build-dir.
Cargo now organizes build-dir by build step instead of by file type. It also moves the hash from the file name to the parent directory. As a result, Cargo applies the build-configuration hash to all content in build-dir.
This work began with the build directory layout project goal in 2025. Its stabilization is a milestone toward a new cross-workspace cache project goal. The new layout unblocks future improvements such as cache garbage collection, cross-workspace cache deduplication, cross-workspace caching, and fine-grained locking. The changes went through a call for testing in March 2026.
Cargo can hold back newly published dependency versions
Automated scanners and community members often catch malicious package versions within hours or days of publication. Rust 1.100 stabilizes Cargo’s minimum publish age. A project can opt in to wait for that window before dependency resolution selects newly published versions. This practice is also known as dependency cooldowns. For example, this .cargo/config.toml entry sets a three-day minimum publish age:
[registry]
global-min-publish-age = "3 days"See the Cargo configuration reference.
When Cargo selects versions, it skips any version published more recently than the minimum publish age. It also reports what it held back.
$ cargo update
Updating crates.io index
Locking 2 packages to highest compatible version as of min-publish-age
Adding cc v1.11.0 (available: v1.18.0, published 3 hours ago)
Adding clap 4.6.7 (available: 4.6.9, published 2 days ago)To use a new version immediately, override the minimum publish age for a single update:
$ CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update clap --precise 4.6.9
Updating crates.io index
Updating clap 4.6.7 -> clap 4.6.9 (published 2 days ago, minimum age 3 days)Cargo records the newer version in Cargo.lock and keeps it until a later cargo update resolves it again.
- The registry must record when each version was published. Versions without a
pubtimefield in the index are never held back. cargo installignores the minimum publish age for both the installed crate and its dependencies. Pin a version withcargo install foo@1.2.3if needed.- A minimum publish age reduces the risk from some supply chain attacks. It is not a complete defense on its own. Keep reviewing dependency updates as usual.
Further work to protect the ecosystem is planned under the crates.io supply chain hardening project goal. That work includes quarantine support and automated detection of suspicious releases.