Cfg! in lazy_static

I have a:

if cfg!(feature = "internal") {
  // blah
}

I have it in two different different files -- in one everything works as expected, the other seems to be silently ignored. The only notable difference I can think of is that the latter one is within a lazy_static block.

Is it expected that cfg! within lazy_static! not work?

It should work fine. Perhaps post an example and explain in what manner it fails?

By "the other seems to be silently ignored", do you mean that the compiler gives you compile-time errors when the feature is disabled?

If that's what's happening you can fix it by changing the code to:

#[cfg(feature = "internal")]
{
    // blah
}
1 Like

It was a typo. features :expressionless:

I don't know why, but I had gotten the impression that it would error out of the feature key is not recognized. Lesson learned!

2 Likes