NewNode 26.14: mockResolvedValue and Friends in node:test →
w3/w3-tutorials

Rust 1.100: the never type, DropGuard and Cargo cooldowns

What changed in Rust 1.100, with runnable examples: the never type fallback change that can break your build, DropGuard, custom allocators, and Cargo dependency cooldowns.

Updated Nov 15, 20267 min readIntermediaterust 1.100.0

Rust 1.100 shipped on November 12, 2026. It is a big one: the never type is finally stable, custom allocators work with Vec and Box, DropGuard gives you cleanup on every exit path, and Cargo can now hold back freshly published crates. There is also one breaking change for code on editions 2015 to 2021.

This guide walks through the changes worth acting on, with examples that compile on 1.100.0.

Upgrade

terminal
rustup update stable
rustc --version
text
rustc 1.100.0 (0ef1bc386 2026-11-09)

If rustc --version still prints an older version, check which rustc. A rustc installed with Homebrew can sit earlier in PATH than the one rustup manages.

To try 1.100 in one project without changing your default, pin it in rust-toolchain.toml:

rust-toolchain.toml
[toolchain]
channel = "1.100.0"

1. Check the never type fallback change first

This is the change that can stop your build. In editions before 2024, when the compiler could not infer a type for an expression that never produces a value, it fell back to (). Rust 1.100 changes that fallback to ! in all editions, as edition 2024 already did. It was needed to make Infallible an alias for !.

Most code won't notice. The common breakage is a generic function whose return value is thrown away:

src/main.rs
fn load<T: Default>() -> Result<T, String> {
    Ok(T::default())
}

fn run() -> Result<(), String> {
    load()?;
    Ok(())
}

Nothing pins down T, so it used to fall back to (). On Rust 1.89 with edition 2021, this compiles with a warning that it "will become a hard error in Rust 2024 and in a future release in all editions". On 1.100 it is that hard error:

text
error[E0277]: the trait bound `!: Default` is not satisfied
 --> src/main.rs:6:5
  |
6 |     load()?;
  |     ^^^^^^ the trait `Default` is not implemented for `!`
  |
  = help: you might have intended to use the type `()` here instead

The fix is to name the type you meant:

rust
load::<()>()?;

2. Use ! anywhere a type goes

Before 1.100 you could only write ! as a function's return type. Now it works anywhere, such as an error type that can never happen:

rust
fn infallible_unwrap<T>(res: Result<T, !>) -> T {
    let Ok(v) = res;
    v
}

fn parse_config(input: &str) -> Result<String, !> {
    Ok(input.trim().to_uppercase())
}

let Ok(v) = res; needs no else branch, because the compiler knows Err can't be built. Since Infallible is now an alias for !, older APIs fit straight in:

rust
use std::convert::Infallible;

fn old_api() -> Result<u8, Infallible> {
    Ok(7)
}

fn main() {
    // Result<u8, Infallible> is now the same type as Result<u8, !>
    println!("{}", infallible_unwrap(old_api()));
}
text
7

Use ! in new code where you would have reached for Infallible. There is no need to rewrite existing Infallible uses, since they are now the same type.

3. Roll back on failure with DropGuard

std::mem::DropGuard wraps a value and runs a closure when the guard is dropped. That covers every way out of a function: return, ? and panics. Call DropGuard::dismiss to get the value back without running the closure.

That makes all-or-nothing updates short. This parser leaves the vector untouched if any input fails:

rust
use std::mem::DropGuard;
use std::num::ParseIntError;

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);
    });
    for s in strings {
        nums.push(s.parse()?);
    }
    DropGuard::dismiss(nums);
    Ok(())
}

fn main() {
    let mut nums = vec![1, 2];
    let bad = parse_all(&mut nums, &["3", "x", "5"]);
    println!("after bad input: {nums:?} ({})", bad.unwrap_err());
    parse_all(&mut nums, &["3", "4"]).unwrap();
    println!("after good input: {nums:?}");
}
text
after bad input: [1, 2] (invalid digit found in string)
after good input: [1, 2, 3, 4]

The 3 was pushed before x failed, and the guard removed it. Inside the loop, nums.push works because the guard derefs to the wrapped value.

Use DropGuard for one-off cleanup in a single function. If the same cleanup belongs to a type everywhere it's used, a Drop impl on that type is still the better fit.

4. Plug a custom allocator into Vec and Box

The core of the allocator API is now stable. Implement the Allocator trait, then pass your allocator to Vec::new_in, Vec::with_capacity_in or Box::new_in. This one counts allocations and hands the real work to the global allocator:

rust
use std::alloc::{Allocator, AllocError, Global, Layout};
use std::ptr::NonNull;
use std::sync::atomic::{AtomicUsize, Ordering};

struct Counting<'a> {
    count: &'a AtomicUsize,
}

unsafe impl Allocator for Counting<'_> {
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        self.count.fetch_add(1, Ordering::Relaxed);
        Global.allocate(layout)
    }
    unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
        unsafe { Global.deallocate(ptr, layout) }
    }
}

fn main() {
    let count = AtomicUsize::new(0);
    let alloc = Counting { count: &count };
    let mut v = Vec::new_in(&alloc);
    for i in 0..100 {
        v.push(i);
    }
    let b = Box::new_in(42, &alloc);
    println!("vec len {}, box {}, allocations: {}", v.len(), b, count.load(Ordering::Relaxed));
}
text
vec len 100, box 42, allocations: 7

Six of those allocations come from the Vec growing as it fills up, and one from the Box. Allocating with Vec::with_capacity_in(100, &alloc) instead would need a single allocation for the vector.

The trait is unsafe to implement, because the standard library trusts it to return valid memory. Only Vec and Box accept custom allocators for now. Other collections are planned under the Allocators 1.0 project goal. Arena and bump allocators, per-request memory pools and allocation tracking in tests can now be done on stable.

5. Let Cargo find unused dependencies

Cargo now warns about entries in [dependencies] that no build target uses:

text
warning: unused dependency `itoa`
 --> Cargo.toml:7:1
  |
7 | itoa = "1.0.19"
  | ^^^^^^^^^^^^^^^
  |
  = note: `cargo::unused_dependencies` is set to `warn` by default
help: consider removing the dependency on `itoa`

The warning only appears when you build every target that could use the dependency. cargo check --bin foo stays quiet, since another binary might need it. [dev-dependencies] are never checked.

To fail CI on unused dependencies, raise the lint in Cargo.toml:

Cargo.toml
[lints.cargo]
unused_dependencies = "deny"

The Cargo lints reference lists the other lints in this new system.

6. Hold back fresh releases with dependency cooldowns

Malicious crate versions are usually caught within hours or days of being published. global-min-publish-age tells Cargo to ignore versions newer than a set age when it resolves dependencies:

.cargo/config.toml
[registry]
global-min-publish-age = "7 days"

Cargo then shows you what it held back:

terminal
cargo update
text
    Updating crates.io index
     Locking 11 packages to highest Rust 1.100.0 compatible versions as of 7 days ago
      Adding itoa v1.0.18 (available: v1.0.19, published 4 days ago)
      Adding syn v3.0.9 (available: v3.0.10, published 4 days ago)

When you need a new version now, such as a security fix, override the check for one update:

terminal
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow cargo update itoa --precise 1.0.19
text
    Updating crates.io index
    Updating itoa v1.0.18 -> v1.0.19 (published 4 days ago, minimum age 7 days)

The pinned version is kept in Cargo.lock until something re-resolves it. A plain cargo update run before the cooldown ends counts, and moves you back:

text
 Downgrading itoa v1.0.19 -> v1.0.18 (available: v1.0.19, published 4 days ago)

Two more catches:

  • cargo add pins the newest version as the minimum. It wrote itoa = "1.0.19", a version only 4 days old. With a longer cooldown, resolving failed outright: version 1.0.19 is too new (published 4 days ago, minimum age 60 days). Cargo's help suggests downgrading the requirement to "1.0.18". Loose requirements such as "1" give the resolver room to pick an older version.
  • cargo install ignores the setting, for the crate and its dependencies. Pin with cargo install [email protected] if that matters.

A cooldown of a few days is a cheap default for applications. It reduces the risk from some supply chain attacks, but it doesn't replace reviewing your dependency updates.

Smaller changes

  • Build directory layout. Cargo now organises the build directory by build step, with the configuration hash in the directory name. This cuts down extra and missed rebuilds, especially across git worktrees. Scripts that reach into target/ for intermediate files may break. See cargo#17287 for workarounds.
  • std::mem::conjure_zst is the official, unsafe way to create a value of a zero-sized type. Use it instead of transmuting ().
  • New helpers: bool::toggle, str::trim_prefix and str::trim_suffix, Vec::from_fn, and Box::map, Rc::map and Arc::map.
rust
let mut flag = false;
flag.toggle();
println!("toggle: {flag}");
println!("trim_prefix: {}", "v1.100.0".trim_prefix('v'));
text
toggle: true
trim_prefix: 1.100.0

Next steps

Related tutorials