ICP·DevICP·Dev
Back to articles
RustJune 24, 20262 min read

Beyond Crate Creep: How Rust 1.95’s New `cfg_select!` Declares War on Dependency Bloat

The release of Rust 1.95.0 introduces the built-in `cfg_select!` macro, eliminating the need for the popular `cfg-if` crate and tackling dependency creep. Alongside `if let` match guards and updated target boundaries, Rust is compressing common engineering pain points directly into its stable core.

Key takeaways

  • The release of Rust 1.95.0 introduces the built-in `cfg_select!` macro, eliminating the need for the popular `cfg-if` crate and tackling dependency creep
  • Alongside `if let` match guards and updated target boundaries, Rust is compressing common engineering pain points directly into its stable core
Share
Beyond Crate Creep: How Rust 1.95’s New `cfg_select!` Declares War on Dependency Bloat

Beyond Crate Creep: How Rust 1.95’s New cfg_select! Declares War on Dependency Bloat

In a mature programming ecosystem, progress isn't just about adding shiny new features; it’s about compressing developer pain. With the release of Rust 1.95.0, the Rust team has taken a direct, pragmatic swipe at one of the community's most persistent headaches: dependency sprawl.

Historically, Rustaceans aiming to write cross-platform software were forced to choose between a messy tower of cascading #[cfg(...)] attributes or pulling in the third-party cfg-if crate to keep code readable. The debut of the built-in cfg_select! macro fundamentally changes this equation, signaling a quiet shift away from the "reach-for-a-crate" reflex and toward a more self-contained, stable standard library.

The Problem: A Wall of Fragmented #[cfg] Attributes

When compiling code for multiple targets (e.g., Linux, Windows, or WebAssembly), writing mutually exclusive platform paths is notoriously clunky. Stacking multiple #[cfg] blocks scatters code and splits developer intent:

rust
#[cfg(unix)]
fn get_shell() -> &'static str { "/bin/sh" }

#[cfg(windows)]
fn get_shell() -> &'static str { "cmd.exe" }

If you forget to declare a fallback for WebAssembly, the compiler won't warn you until someone attempts to build on that unsupported target. While the external cfg-if crate solved this elegantly, relying on micro-crates introduces supply-chain risk and increases audit overhead.

Enter cfg_select!: Native Compile-Time Matching

With Rust 1.95, the standard library absorbs this capability. The new cfg_select! macro functions like a compile-time match block over configuration predicates, evaluating them top to bottom and emitting only the first branch that evaluates to true.

rust
let is_windows_str = cfg_select! {
    windows => "windows",
    _ => "not windows",
};

Because branches are structurally bound together, missing platforms or logic gaps are caught instantly. Best of all, it operates cleanly in expression position, allowing you to bind platform-specific variables dynamically without wrapping entire variable declarations in separate attribute blocks.

A professional, modern 3D infographic explaining c...

Flattening Code with if let Match Guards

Rust 1.95 also introduces if let guards inside match expressions. Building on the let-chains stabilized in Rust 1.88, this feature drastically flattens deeply nested matching logic.

Instead of writing nested match statements to verify a computed result on an active variable, developers can now combine pattern-driven checks into a single line:

rust
match value {
    Some(x) if let Ok(y) = compute(x) => {
        // Both `x` and `y` are in scope here!
        println!("Value: {}, Computation: {}", x, y);
    }
    _ => {}
}

This keeps high-throughput data-processing pipelines dense, highly readable, and performant.

Gating Low-Level Customizations

To further secure the ecosystem, Rust 1.95 also removes stable support for custom JSON target specifications in rustc. By gating this low-level extensibility behind -Z unstable-options (requiring nightly features), the compiler team is drawing a sharp line around what constitutes fully stable Rust.

By eliminating dependency creep at the compiler level and enforcing strict platform boundaries, Rust 1.95 guarantees that safe, cross-platform software remains easy to write, review, and trust.

Tags

#Rust 1.95#Compiler#Programming#Open Source#Development

Grounded sources & citations

What to read next

Enjoyed this? Get the next one

Subscribe to the newsletter and the next playbook lands in your inbox — no spam, unsubscribe anytime.