Login
You're viewing the techdon.dev public feed.
  • Apr 16, 2026, 1:29 PM

    The `cfg_select` macro is finally stable in today's rust 1.95 release

    blog.rust-lang.org/2026/04/16/

    It's a flexible way of picking an implementation based on information known at compile time, like the current target or a cargo feature.

    I worked on the implementation of this macro in the compiler and pushing for its stabilization (updating tests, docs, the reference, etc.)

    #rustlang

    cfg_select in action

cfg_select! {
    feature = "nightly" => {
        pub use core::hint::likely;
    }
    _ => {
        #[inline(always)]
        pub fn likely(b: bool) -> bool {
            #[cold]
            fn cold_path() {}

            if !b {
                cold_path()
            }

            b
        }
    }
}
    cfg_select in action in a macro

#[unsafe(link_section = cfg_select!(
    target_object_format = "mach-o" => "__TEXT,foobar",
    _ => ".foobar",
))]
#[unsafe(no_mangle)]
extern "C" fn foo() {}
    💬 0🔄 6⭐ 4