joshlf
April 14, 2017, 7:32pm
1
Is it possible to use conditional compilation to include or exclude compiler attributes? For example, something like:
#[cfg(feature = "no-inline")]
#[inline(never)]
fn foo() {}
(in my case, I'm trying to turn off inlining so I can get more granular instrumentation of my code)
ogeon
April 14, 2017, 8:37pm
2
Yes, you should be able to use cfg_attr
:
#![cfg_attr(feature = "no-inline", inline(never))]
fn foo() {}
joshlf
April 14, 2017, 9:02pm
3
Awesome, thanks! Also, it's #[cfg_attr()]
, not #![cfg_attr()]
(or at least, the latter worked for me while the former gave me errors: "an inner attribute is not permitted in this context").
ogeon
April 15, 2017, 1:11am
4
Ah, yes, one applies to the whole file/program and one applies to a single item. I copied a global one and forgot to change it.