You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use of feature flagged functions in std::cfg macro #71679
I expected to see this compile based on the std::cfg macro docs, instead, this it failed to compile. This was confusing, as I was able to write this, in a slightly less clear way, using cfg attributes. The documentation calls out the links between the two, saying The syntax given to this macro is the same syntax as the cfg attribute.
Should the docs for std::cfg be updated to state that both branches of the if/else need to be valid regardless of the cfg! condition? Or is this something that would be expected to compile?
Meta
This was tested on 1.42.0, but from compiler explorer, this shows up in all versions since 1.0.0 rustc --version --verbose:
We can update the docs, for sure, but I'm not sure what to say -- maybe something like "this simply evaluates to true/false"? cfg! is basically not special to the compiler, it doesn't ever remove code, so everything still needs to compile (unlike #[cfg(...)] which will remove code if the expression doesn't evaluate to true).
To rephrase, slightly, how about adding the following to the docs:
cfg!, unlike #[cfg(...)], does not remove any code and only evaluates to true or false. For example, this means all code in an if/else block needs to be valid when cfg! is used for the condition, regardless of what cfg! is evaluating.
Activity
Add feature to prost-build to allow runtime specification of protoc
Mark-Simulacrum commentedon Apr 29, 2020
We can update the docs, for sure, but I'm not sure what to say -- maybe something like "this simply evaluates to true/false"?
cfg!is basically not special to the compiler, it doesn't ever remove code, so everything still needs to compile (unlike#[cfg(...)]which will remove code if the expression doesn't evaluate to true).dfreese commentedon Apr 29, 2020
To rephrase, slightly, how about adding the following to the docs:
cfg!, unlike#[cfg(...)], does not remove any code and only evaluates to true or false. For example, this means all code in an if/else block needs to be valid whencfg!is used for the condition, regardless of whatcfg!is evaluating.Add feature to prost-build to allow runtime specification of protoc
Add clarification on std::cfg macro docs v. #[cfg] attribute
Rollup merge of rust-lang#71692 - dfreese:cfgdocs, r=kennytm
Add feature to prost-build to allow runtime specification of protoc
Add feature to prost-build to allow runtime specification of protoc
Add feature to prost-build to allow runtime specification of protoc
Add feature to prost-build to allow runtime specification of protoc
Add feature to prost-build to allow runtime specification of protoc