Folkert de Vriesfolkertdev@hachyderm.io
Apr 16, 2026, 1:29 PMThe `cfg_select` macro is finally stable in today's rust 1.95 release
https://blog.rust-lang.org/2026/04/16/Rust-1.95.0/
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.)
![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
}
}
}](https://techdon.dev/system/cache/media_attachments/files/116/414/688/932/075/733/small/26a920523678f7fa.png)
![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() {}](https://techdon.dev/system/cache/media_attachments/files/116/414/688/951/548/851/small/25c54099972fb1ca.png)